Ledger Nano X - The secure hardware wallet
SHARE
TWEET

twitter_api_1.1_backup

baptx Oct 5th, 2014 (edited) 380 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Twitter API 1.1 tweets / favorites (likes) / following / followers backup in web browser
  2.  * Get your access keys to use Twitter API 1.1: https://dev.twitter.com/docs/auth/tokens-devtwittercom
  3.  * 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 a web browser console (F12 or Ctrl+Shift+K shortcut)
  4.  * A textarea will appear so you can copy/paste to save data as a CSV file or search tweets / users in your web browser (Ctrl+F shortcut)
  5.  * You can then view your backup in a spreadsheet editor like LibreOffice Calc
  6.  * You can also compare the backup with another one to see who unfollowed you or who changed their Twitter username by looking at the user ID (e.g. with the Linux diff command)
  7.  *
  8.  * Note about the tweets backup:
  9.  * Usually you will search tweets that you retweeted using Twitter web version (https://twitter.com/search) with a search like "from:your_username filter:nativeretweets keyword"
  10.  * But it is limited to the retweets of the last 7 days, like for the free version of the search API (https://developer.twitter.com/en/docs/tweets/search/overview/standard)
  11.  * An alternative is to search tweets in your user timeline with this script but it is limited to your last 3200 tweets (including retweets and replies)
  12.  * This script can be combined with the Twitter feature to backup data, which is not limited to your last 3200 tweets but you can only request a backup every 30 days
  13.  * To find tweets that you retweeted or favorited / liked from a specific person, you can open the CSV file with LibreOffice Calc, click on the column you want to search and press Ctrl+H to search a username
  14. */
  15.  
  16.  
  17. var url = "https://api.twitter.com/1.1/statuses/user_timeline.json"
  18. //var url = "https://api.twitter.com/1.1/favorites/list.json";
  19. //var url = "https://api.twitter.com/1.1/friends/list.json";
  20. //var url = "https://api.twitter.com/1.1/followers/list.json";
  21.  
  22. var accessor = {
  23.     token: "XXX",
  24.     tokenSecret: "XXX",
  25.     consumerKey : "XXX",
  26.     consumerSecret: "XXX"
  27. };
  28. var message = {
  29.     action: url,
  30.     method: "GET",
  31.     parameters: {
  32.         screen_name: "baptx",
  33.         count: 200,
  34.         callback: "getJSONP"
  35.     }
  36. };
  37.  
  38. var out = [];
  39. var length = -1;
  40. var start = 0;
  41. var next = -1;
  42. var res;
  43.  
  44. function getJSONP(data)
  45. {
  46.     res = data;
  47. }
  48.  
  49. function loadAPI_tweets()
  50. {
  51.     if (length != 1)
  52.     {
  53.         if (next != -1) {
  54.             message.parameters.max_id = next;
  55.         }
  56.         OAuth.completeRequest(message, accessor);
  57.         OAuth.SignatureMethod.sign(message, accessor);
  58.  
  59.         var script3 = document.createElement("script");
  60.         script3.setAttribute("src", url + '?' + OAuth.formEncode(message.parameters));
  61.         document.body.appendChild(script3);
  62.         script3.addEventListener("load", function() {
  63.             length = res.length;
  64.             for (var i = 0; i < length; ++i) {
  65.                 var text;
  66.                
  67.                 if (res[i].retweeted_status) {
  68.                     text = res[i].retweeted_status.full_text;
  69.                     name = res[i].retweeted_status.user.screen_name;
  70.                 } else {
  71.                     text = res[i].full_text;
  72.                     name = res[i].user.screen_name;
  73.                 }
  74.                
  75.                 out[start + i] = res[i].created_at + '\t'
  76.                     + name + '\t"'
  77.                     + text.replace(/"/g, '""') + '"\t"""'
  78.                     + res[i].id_str + '"""';
  79.                 // CSV with tab separator: quote to allow multiline string; escape quote string delimiter with double quote; display large numbers correctly as string with triple quote
  80.             }
  81.             next = res[length - 1].id_str;
  82.             start += length - 1;
  83.             loadAPI_tweets();
  84.         });
  85.     }
  86.     else
  87.     {
  88.         displayData();
  89.     }
  90. }
  91.  
  92. function loadAPI_users()
  93. {
  94.     if (length == -1 || res.next_cursor_str != 0) {
  95.         message.parameters.cursor = next;
  96.         OAuth.completeRequest(message, accessor);
  97.         OAuth.SignatureMethod.sign(message, accessor);
  98.  
  99.         var script3 = document.createElement("script");
  100.         script3.setAttribute("src", url + '?' + OAuth.formEncode(message.parameters));
  101.         document.body.appendChild(script3);
  102.         script3.addEventListener("load", function() {
  103.             length = res.users.length;
  104.             for (var i = 0; i < length; ++i) {
  105.                 out[start + i] = res.users[i].screen_name + '\t'
  106.                     + res.users[i].name.replace(/"/g, '""') + '\t"""'
  107.                     + res.users[i].id + '"""';
  108.             }
  109.             next = res.next_cursor_str;
  110.             start += length;
  111.             loadAPI_users();
  112.         });
  113.     }
  114.     else {
  115.         displayData();
  116.     }
  117. }
  118.  
  119. function displayData()
  120. {
  121.     var box = document.createElement("textarea");
  122.     box.value = out.join('\n');
  123.     document.body.appendChild(box);
  124. }
  125.  
  126. var script = document.createElement("script");
  127. script.setAttribute("src", "https://pastebin.com/raw/HFjqYLdG"); // http://oauth.googlecode.com/svn/code/javascript/oauth.js (down)
  128. document.body.appendChild(script);
  129. script.addEventListener("load", function() {
  130. var script2 = document.createElement("script");
  131.     script2.setAttribute("src", "https://pastebin.com/raw/M0N8JKwf"); // http://pajhome.org.uk/crypt/md5/sha1.js
  132.     document.head.appendChild(script2);
  133.     script2.addEventListener("load", function() {
  134.         if (url == "https://api.twitter.com/1.1/statuses/user_timeline.json" || url == "https://api.twitter.com/1.1/favorites/list.json") {
  135.             message.parameters.include_rts = true; // include retweets
  136.             message.parameters.tweet_mode = "extended"; // needed to get full tweet after API change
  137.             loadAPI_tweets();
  138.         }
  139.         else {
  140.             loadAPI_users();
  141.         }
  142.     });
  143. });
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