samedi 3 décembre 2016

How to use guzzle with twitter API?

Im using guzzle with laravel 5.3 and im trying to access twitters API to retrieve a users timeline. But when I try I keep getting an error that reads {"errors":[{"code":215,"message":"Bad Authentication data."}]}.

This is my code:

public function getUserTimeline() {
    $client = new \GuzzleHttp\Client();
    $token = "user_id-token";
    $secret = "user_secret";
    $request = $client->get('https://api.twitter.com/1.1/statuses/user_timeline.json?', 
                                [ 'query' => [ 'consumer_key' => env('TWITTER_CLIENT_ID'),
                                               'consumer_secret' => env('TWITTER_SECRET'),
                                               'screen_name' => "a_screen_name",
                                               'token' => $token, 
                                               'token_secret' => $secret,
                                               'count'=>'2'
                                             ]]
                           ));
    dd(json_decode($request->getBody()));
}

I've checked and verified the tokens are up to date but It keeps giving me this error. Im not sure what I've missed.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire