Skip to content

Instantly share code, notes, and snippets.

@matthewroach
Created August 15, 2013 08:09
Show Gist options
  • Save matthewroach/6239135 to your computer and use it in GitHub Desktop.
Save matthewroach/6239135 to your computer and use it in GitHub Desktop.
Basic Twitter API call
<cfscript>
consumerKey = '';
consumerSecret = '';
accessToken = '';
accessSecret = '';
epochTime = left( epoch(now()), 10 );
twitterEndpoint = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
// twitterEndpoint = 'https://api.twitter.com/1.1/favorites/list.json';
// twitterEndpoint = 'https://api.twitter.com/1.1/application/rate_limit_status.json';
oauth_signature = "#hmac('GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fuser_timeline.json&oauth_consumer_key%3D#consumerKey#%26oauth_nonce%3Dfedb3d02f0f8c94e6c00e10a9058fdee%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#epochTime#%26oauth_token%3D#accessToken#%26oauth_version%3D1.0','#consumerSecret#&#accessSecret#', 'HmacSHA1')#";
header_value ='OAuth oauth_consumer_key="#consumerKey#", oauth_nonce="fedb3d02f0f8c94e6c00e10a9058fdee", oauth_signature="#urlencodedformat(oauth_signature)#", oauth_signature_method="HMAC-SHA1", oauth_timestamp="#epochTime#", oauth_token="#accessToken#", oauth_version="1.0"';
params = [
{ "type" : "header", "name" : "Authorization", "value" : header_value },
{ "type" : "header", "name" : "Content-Type", "value" : "application/x-www-form-urlencoded" }
];
twitter = HTTP(
method : "GET",
url : twitterEndpoint,
httpparams : params,
result : 'twitterJSON'
);
tJSON = deserializeJSON(twitter.fileContent);
</cfscript>
<cfdump var="#tJSON#" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment