Last active
August 29, 2015 14:09
-
-
Save hamzamu/5e28349b27ca040e40b0 to your computer and use it in GitHub Desktop.
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
var crypto = Npm.require('crypto'), | |
consumerKey = 'consumerKey', | |
consumerSecret = 'consumerSecret', | |
accessToken = 'accessToken', | |
accessTokenSecret = 'accessTokenSecret', | |
url = 'https://api.twitter.com/1.1/statuses/home_timeline.json', | |
date = new Date, | |
method = 'GET'; | |
// Note that the keys are in alphabetical order | |
var reqObj = { | |
oauth_consumer_key: consumerKey, | |
oauth_nonce: Math.random().toString(36).replace(/[^a-z]/, '').substr(2), | |
oauth_signature_method: 'HMAC-SHA1', | |
oauth_timestamp: Math.floor(date.getTime() / 1000), | |
oauth_token: accessToken, | |
oauth_version: '1.0'//, | |
//search_expression: 'banana' //add here request param if necessary | |
}; | |
// construct a param=value& string and uriEncode | |
var paramsStr = ''; | |
for (var i in reqObj) { | |
paramsStr += "&" + i + "=" + reqObj[i]; | |
} | |
// yank off that first "&" | |
paramsStr = paramsStr.substr(1); | |
var sigBaseStr = method + "&" | |
+ encodeURIComponent(url) | |
+ "&" | |
+ encodeURIComponent(paramsStr); | |
consumerSecret += "&" + accessTokenSecret; | |
var hashedBaseStr = crypto.createHmac('sha1', consumerSecret).update(sigBaseStr).digest('base64'); | |
// Add oauth_signature to the request object | |
reqObj.oauth_signature = encodeURIComponent(hashedBaseStr); | |
var authorization = 'OAuth '; | |
for (var i in reqObj) { | |
authorization += i + '="'+ reqObj[i] + '",'; | |
} | |
Meteor.http.call(method, url, | |
{headers: {Authorization: authorization}}, | |
function (error, result) { | |
if (!error) { | |
console.log(result); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment