Last active
March 30, 2021 11:26
-
-
Save baptx/ffb268758cd4731784e3 to your computer and use it in GitHub Desktop.
Access Twitter API 1.1 in web browser
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
/* Access Twitter API 1.1 in browser. | |
** Get your access keys to use Twitter API 1.1: https://dev.twitter.com/docs/auth/tokens-devtwittercom | |
** Format JSON in Firefox: https://addons.mozilla.org/EN-us/firefox/addon/jsonview/ | |
** You can change Twitter API URL and Twitter screen_name, then execute script from a trusted web page without CSP protection like about:blank in Firefox Scratchpad or any other browser console. | |
*/ | |
var script = document.createElement("script"); | |
script.setAttribute("src", "https://pastebin.com/raw/HFjqYLdG"); // http://oauth.googlecode.com/svn/code/javascript/oauth.js (down) | |
document.body.appendChild(script); | |
script.addEventListener("load", function() { | |
var script2 = document.createElement("script"); | |
script2.setAttribute("src", "https://pastebin.com/raw/M0N8JKwf"); // http://pajhome.org.uk/crypt/md5/sha1.js | |
document.head.appendChild(script2); | |
script2.addEventListener("load", function() { | |
var url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; | |
var accessor = { | |
token: "XXX", | |
tokenSecret: "XXX", | |
consumerKey : "XXX", | |
consumerSecret: "XXX" | |
}; | |
var message = { | |
action: url, | |
method: "GET", | |
parameters: {screen_name: "jack"} | |
}; | |
OAuth.completeRequest(message, accessor); | |
OAuth.SignatureMethod.sign(message, accessor); | |
document.location = url + '?' + OAuth.formEncode(message.parameters); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment