Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Make a developers account on twitter, create an app and get the consumer key/secret. */
- $key = '[key here]';
- $secret = '[secret here'];
- $postdata = http_build_query(array('grant_type' => 'client_credentials'));
- $opts = array('http' => array('method' => 'POST',
- 'header' => "Authorization: Basic ".base64_encode($key . ':' . $secret)."\r\nContent-Type: application/x-www-form-urlencoded;charset=UTF-8",
- 'content' => $postdata));
- $context = stream_context_create($opts);
- $data = json_decode(file_get_contents('https://api.twitter.com/oauth2/token', false, $context));
- echo $data->access_token;
- /* get this access_token and write it down somewhere. */
- /* Now to use the Twitter API */
- $access_token = '[access code here]';
- $opts = array('http' => array('method' => 'GET',
- 'header' => "Authorization: Bearer " . $access_token . "\r\nContent-Type: application/x-www-form-urlencoded;charset=UTF-8"));
- $context = stream_context_create($opts);
- $data = json_decode(file_get_contents('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2', false, $context));
- var_dump($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement