Skip to content

Instantly share code, notes, and snippets.

@h5y1m141
Created June 27, 2012 12:00
Show Gist options
  • Save h5y1m141/3003641 to your computer and use it in GitHub Desktop.
Save h5y1m141/3003641 to your computer and use it in GitHub Desktop.
chrome extention sample
var api = 'http://api.twitter.com/1/statuses/home_timeline.json' ;
var OAUTH_CONSUMER_KEY = 'XXX' ;
var OAUTH_CONSUMER_SECRET = 'XXX' ;
var OAUTH_ACCESS_TOKEN = 'XXX' ;
var OAUTH_ACCESS_SECRET = 'XXX' ;
main();
function main() {
var accessor = {
consumerSecret: OAUTH_CONSUMER_SECRET,
tokenSecret: OAUTH_ACCESS_SECRET
} ;
var message = {
method: "GET",
action: api,
parameters: {
oauth_signature_method: "HMAC-SHA1",
oauth_consumer_key: OAUTH_CONSUMER_KEY,
oauth_token: OAUTH_ACCESS_TOKEN
}
} ;
OAuth.setTimestampAndNonce( message ) ;
OAuth.SignatureMethod.sign( message, accessor ) ;
var target = OAuth.addToURL( message.action, message.parameters ) ;
var options = {
type: message.method,
url: target,
dataType: 'json',
success: function(data) {
onText(data);
},
error: function( a ) {
window.alert( a.responseText ) ;
},
timeout: 1000 * 50
};
$.ajax( options ) ;
}
function onText( data ) {
for( var i = 0; i < data.length; i++ ) {
var path = data[i].user.profile_image_url;
var userName = data[i].user.name;
var screenName = data[i].user.screen_name;
var tweet = data[i].text ;
$(document.body).append($("<img>").attr("src", path));
$(document.body).append($("<br />"));
$(document.body).append($("<p>").text(tweet));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment