-
-
Save shivakrishna9/2e40b0a204c2f11ebba9dc5f0b454b8f to your computer and use it in GitHub Desktop.
Twitter API 1.1 favorites/following/followers backup
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
| /* Twitter API 1.1 favorites/following/followers backup (a textarea will appear so you can copy/paste to save data). | |
| ** 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 web page like https://api.twitter.com/1.1 in Firefox Scratchpad or any other browser console. | |
| */ | |
| var url = "https://api.twitter.com/1.1/favorites/list.json"; | |
| //var url = "https://api.twitter.com/1.1/friends/list.json"; | |
| //var url = "https://api.twitter.com/1.1/followers/list.json"; | |
| var accessor = { | |
| token: "XXX", | |
| tokenSecret: "XXX", | |
| consumerKey : "XXX", | |
| consumerSecret: "XXX" | |
| }; | |
| var message = { | |
| action: url, | |
| method: "GET", | |
| parameters: { | |
| screen_name: "baptx", | |
| count: 200, | |
| callback: "getJSONP"} | |
| }; | |
| var out = []; | |
| var length = -1; | |
| var start = 0; | |
| var next = -1; | |
| var res; | |
| function getJSONP(data) | |
| { | |
| res = data; | |
| } | |
| function loadAPI_favorites() | |
| { | |
| if (length != 1) | |
| { | |
| if (next != -1) | |
| message.parameters.max_id = next; | |
| OAuth.completeRequest(message, accessor); | |
| OAuth.SignatureMethod.sign(message, accessor); | |
| var script3 = document.createElement("script"); | |
| script3.setAttribute("src", url + '?' + OAuth.formEncode(message.parameters)); | |
| document.body.appendChild(script3); | |
| script3.addEventListener("load", function() { | |
| length = res.length; | |
| for (var i = 0; i < length; i++) | |
| out[start + i] = res[i].created_at + "\t@" + res[i].user.screen_name + ": " + res[i].text + "\t" + "(tweet ID: " + res[i].id_str + ")"; | |
| next = res[length - 1].id_str; | |
| start += length - 1; | |
| loadAPI_favorites(); | |
| }); | |
| } | |
| else | |
| { | |
| var box = document.createElement("textarea"); | |
| box.value = out.join('\n'); | |
| document.body.appendChild(box); | |
| } | |
| } | |
| function loadAPI_following_followers() | |
| { | |
| if (length == -1 || res.next_cursor_str != 0) | |
| { | |
| message.parameters.cursor = next; | |
| OAuth.completeRequest(message, accessor); | |
| OAuth.SignatureMethod.sign(message, accessor); | |
| var script3 = document.createElement("script"); | |
| script3.setAttribute("src", url + '?' + OAuth.formEncode(message.parameters)); | |
| document.body.appendChild(script3); | |
| script3.addEventListener("load", function() { | |
| length = res.users.length; | |
| for (var i = 0; i < length; i++) | |
| out[start + i] = res.users[i].screen_name; | |
| next = res.next_cursor_str; | |
| start += length; | |
| loadAPI_following_followers(); | |
| }); | |
| } | |
| else | |
| { | |
| var box = document.createElement("textarea"); | |
| box.value = out.join('\n'); | |
| document.body.appendChild(box); | |
| } | |
| } | |
| var script = document.createElement("script"); | |
| script.setAttribute("src", "http://oauth.googlecode.com/svn/code/javascript/oauth.js"); | |
| document.body.appendChild(script); | |
| script.addEventListener("load", function() { | |
| var script2 = document.createElement("script"); | |
| script2.setAttribute("src", "http://pajhome.org.uk/crypt/md5/sha1.js"); | |
| document.head.appendChild(script2); | |
| script2.addEventListener("load", function() { | |
| (url == "https://api.twitter.com/1.1/favorites/list.json") ? loadAPI_favorites() : loadAPI_following_followers(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment