-
-
Save twotix/5483949 to your computer and use it in GitHub Desktop.
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
| function getLotsOfFriendAndFo(){ | |
| // NOTE: before using running this script clear any existing data (apart from the header row) from the target sheet | |
| var sheetName = "Followers"; // enter the sheet name to update | |
| var friendOrFo = "followers"; // options 'friends' or 'followers | |
| var optScreenName = "mhawksey"; // if you are getting someone elses friends or followers enter their screen name here | |
| var statusString = ""; | |
| var your_screen_name = tw_request("GET", "account/verify_credentials.json").screen_name; | |
| if (typeof optScreenName != "undefined") { | |
| statusString = "&screen_name="+optScreenName; | |
| your_screen_name = optScreenName; | |
| } | |
| var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
| var sheet = ss.getSheetByName(sheetName); | |
| if (!ScriptProperties.getProperty("cursor")){ | |
| ScriptProperties.setProperty("cursor", "-1"); | |
| } | |
| if (ScriptProperties.getProperty("cursor") != "none"){ // while twitter returns data loop | |
| try { | |
| var o = tw_request("GET", "statuses/"+friendOrFo+".json?cursor=" + ScriptProperties.getProperty("cursor") + statusString); // note using sheetname to build api request | |
| var data = o.users; | |
| for (i in data){ // extracting some subobjects to top level (makes it easier to setRowsData) | |
| if (data[i].status){ | |
| for (j in data[i].status){ | |
| data[i]["status_"+j] = data[i].status[j]; | |
| } | |
| } | |
| if (data[i].screen_name){ // also build url to jump to profile page | |
| data[i]["profile_link"] = "http://twitter.com/"+data[i].screen_name; | |
| //data[i]["friends"] = tw_request("GET", "friendships/exists.json?user_a=" +data[i].screen_name + "&user_b=" + your_screen_name); | |
| //data[i]["friends"] = tw_request("GET", "friendships/exists.json?user_a=" +your_screen_name + "&user_b=" + data[i].screen_name); | |
| } | |
| } | |
| var headRange = sheet.getRange(1, 1, 1, sheet.getMaxColumns()); | |
| var rowIndex = sheet.getLastRow()+1; | |
| data.splice(data.length-1); // remove last row to avoid duplicates | |
| setRowsData(sheet, data, headRange, rowIndex); // dump data for this loop to sheet | |
| if (o.next_cursor!="0"){ | |
| ScriptProperties.setProperty("cursor", o.next_cursor.toString()); // get next cursor | |
| } else { | |
| ScriptProperties.setProperty("cursor", "none"); // break | |
| } | |
| } catch (e) { | |
| Logger.log(e); | |
| } | |
| } | |
| //ss.toast("Done! (You might need to refresh brower to see the results", "Status", 5); | |
| } | |
| function resetGetLotsOfFriendAndFo(){ | |
| ScriptProperties.setProperty("cursor", "-1"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment