Created
June 27, 2012 12:00
-
-
Save h5y1m141/3003641 to your computer and use it in GitHub Desktop.
chrome extention sample
This file contains 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 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