abraham / twitteroauth

The most popular PHP library for use with the Twitter OAuth REST API.
https://twitteroauth.com
MIT License
4.29k stars 1.71k forks source link

Bearer Token #431

Closed mbarwick83 closed 8 years ago

mbarwick83 commented 8 years ago

Do you have an example for using setting/using an application-only bearer token? I looked at your test php file, but couldn't get a full grasp of it. Or maybe this is not possible with this library?

abraham commented 8 years ago

There are two steps.

1) get a bearer token

$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$accessToken = $twitter->oauth2('oauth2/token', array('grant_type' => 'client_credentials'));

2) using a bearer token

$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, null, $accessToken->access_token);
$result = $twitter->get('statuses/user_timeline', array('screen_name' => 'twitterapi'));