Created
May 27, 2015 09:40
-
-
Save ncbateman/c8119b411383bbeeaf82 to your computer and use it in GitHub Desktop.
Twitter Api oAuth 1.1 simple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$consumerKey = /*CONSUMER KEY*/; | |
$consumerSecret = /* CONSUMER SECRET*/; | |
$authContext = stream_context_create(array( | |
'http' => array( | |
'method' => 'POST', | |
'header' => "Authorization: Basic " . base64_encode(($consumerKey).':'.($consumerSecret)) . "\r\n". | |
"Content-type: application/x-www-form-urlencoded;charset=UTF-8\r\n". | |
"Content-Length: 29\r\n". | |
"\r\n". | |
"grant_type=client_credentials", | |
), | |
)); | |
$authResponse = file_get_contents("https://api.twitter.com/oauth2/token", false, $authContext); | |
var_dump($authResponse); | |
$decodedAuth = json_decode($authResponse, true); | |
$bearerToken = $decodedAuth["access_token"]; | |
$data = ['id' => '594023646139654144']; | |
$context = stream_context_create(array( | |
'http' => array( | |
'method' => 'GET', | |
'header' => "Authorization: Bearer " . $bearerToken . "\r\n". | |
"\r\n". | |
"grant_type=client_credentials", | |
), | |
)); | |
$encodedData = file_get_contents('https://api.twitter.com/1.1/statuses/show.json?id='/*TWEET ID HERE*/, false, $context); | |
var_dump(json_decode($encodedData)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment