SHARE
TWEET

twitter_api_1.1_backup

baptx Oct 5th, 2014 (edited) 347 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Twitter API 1.1 favorites/following/followers backup (a textarea will appear so you can copy/paste to save data).
  2. ** Get your access keys to use Twitter API 1.1: https://dev.twitter.com/docs/auth/tokens-devtwittercom
  3. ** Format JSON in Firefox: https://addons.mozilla.org/EN-us/firefox/addon/jsonview/
  4. ** 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.
  5. */
  6.  
  7.  
  8. var url = "https://api.twitter.com/1.1/favorites/list.json";
  9. //var url = "https://api.twitter.com/1.1/friends/list.json";
  10. //var url = "https://api.twitter.com/1.1/followers/list.json";
  11.  
  12. var accessor = {
  13.     token: "XXX",
  14.     tokenSecret: "XXX",
  15.     consumerKey : "XXX",
  16.     consumerSecret: "XXX"
  17. };
  18. var message = {
  19.     action: url,
  20.     method: "GET",
  21.     parameters: {
  22.         screen_name: "baptx",
  23.         count: 200,
  24.         callback: "getJSONP"}
  25. };
  26.  
  27. var out = [];
  28. var length = -1;
  29. var start = 0;
  30. var next = -1;
  31. var res;
  32.  
  33. function getJSONP(data)
  34. {
  35.     res = data;
  36. }
  37.  
  38. function loadAPI_favorites()
  39. {
  40.     if (length != 1)
  41.     {
  42.         if (next != -1)
  43.             message.parameters.max_id = next;
  44.         OAuth.completeRequest(message, accessor);
  45.         OAuth.SignatureMethod.sign(message, accessor);
  46.  
  47.         var script3 = document.createElement("script");
  48.         script3.setAttribute("src", url + '?' + OAuth.formEncode(message.parameters));
  49.         document.body.appendChild(script3);
  50.         script3.addEventListener("load", function() {
  51.             length = res.length;
  52.             for (var i = 0; i < length; i++)
  53.                 out[start + i] = res[i].created_at + "\t@" + res[i].user.screen_name + ": " + res[i].text + "\t" + "(tweet ID: " + res[i].id_str + ")";
  54.             next = res[length - 1].id_str;
  55.             start += length - 1;
  56.             loadAPI_favorites();
  57.         });
  58.     }
  59.     else
  60.     {
  61.         displayData();
  62.     }
  63. }
  64.  
  65. function loadAPI_following_followers()
  66. {
  67.     if (length == -1 || res.next_cursor_str != 0)
  68.     {
  69.         message.parameters.cursor = next;
  70.         OAuth.completeRequest(message, accessor);
  71.         OAuth.SignatureMethod.sign(message, accessor);
  72.  
  73.         var script3 = document.createElement("script");
  74.         script3.setAttribute("src", url + '?' + OAuth.formEncode(message.parameters));
  75.         document.body.appendChild(script3);
  76.         script3.addEventListener("load", function() {
  77.             length = res.users.length;
  78.             for (var i = 0; i < length; i++)
  79.                 out[start + i] = res.users[i].screen_name;
  80.             next = res.next_cursor_str;
  81.             start += length;
  82.             loadAPI_following_followers();
  83.         });
  84.     }
  85.     else
  86.     {
  87.         displayData();
  88.     }
  89. }
  90.  
  91. function displayData()
  92. {
  93.     var box = document.createElement("textarea");
  94.     box.value = out.join('\n');
  95.     document.body.appendChild(box);
  96. }
  97.  
  98. var script = document.createElement("script");
  99. script.setAttribute("src", "https://pastebin.com/raw/HFjqYLdG"); // http://oauth.googlecode.com/svn/code/javascript/oauth.js (down)
  100. document.body.appendChild(script);
  101. script.addEventListener("load", function() {
  102. var script2 = document.createElement("script");
  103.     script2.setAttribute("src", "https://pastebin.com/raw/M0N8JKwf"); // http://pajhome.org.uk/crypt/md5/sha1.js
  104.     document.head.appendChild(script2);
  105.     script2.addEventListener("load", function() {
  106.     (url == "https://api.twitter.com/1.1/favorites/list.json") ? loadAPI_favorites() : loadAPI_following_followers();
  107.     });
  108. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top