Note: Twitter recently wrote to me reminding me that
methods of obtaining and exporting Twitter content obtained via the Twitter API is prohibited by section I.4.A of our API Terms of Service (https://dev.twitter.com/terms/
api-terms ), specifically: You will not attempt or encourage others to sell, rent, lease, sublicense, redistribute, or syndicate access to the Twitter API or Twitter Content to any third party without prior written approval from Twitter. If you provide an API that returns Twitter data, you may only return IDs (including tweet IDs and user IDs). You may export or extract non-programmatic, GUI-driven Twitter Content as a PDF or spreadsheet by using “save as” or similar functionality. Exporting Twitter Content to a datastore as a service or other cloud based service, however, is not permitted.
Following clarification from Twitter I making this template available again but please note.
By using this template you agree it is for personal use only and the data is not made publicly available.
Recently I’ve noticed a growing number of people arrive at this blog having searched for ‘export twitter followers’. Rather than them leaving disappointed here’s a Google Spreadsheet I threw together which allows you to grab a copy of your friends/followers:
*** Google Spreadsheet to Export Twitter Friends and Followers ***
Benefits of using Google Spreadsheet
-
Control – You register for your own API key with Twitter so you have full control of the account
-
Playing with the data – as you are importing straight into a spreadsheet you can do all of your own data manipulation like sorting, filtering and creating your own formula for things like follow/follower ratios
-
Backup – Google Spreadsheets allow you to download copies of spreadsheets in different formats
-
Share – You can make your lists of friends/followers easily viewable
Where’s this all going?
Having already done other things with the Twitter API and Google Spreadsheets (See Populating a Twitter List via Google Spreadsheet … Automatically!, Collect/backup tweets in a Google Spreadsheet, Google Apps Script, Spreadsheets, Twitter and Gadgets) the Twitter/Google Spreadsheet back is well and truly broken. You’ll probably see fewer posts one this area with new stuff instead I’ll probably start properly documenting the little code snippets I use (but if you have any interesting ideas you want help with get in touch).
This doesn’t mean I’ll be walking away from Google Spreadsheets. As recent posts like Turning Google Spreadsheets into a personal or group bookmarking service, show there is huge scope in using Spreadsheets as a very flexible rapid development platform.
Below are some bits of the code used in my new spreadsheet (all the code is viewable via the Script Editor in the Spreadsheet):
function tw_request(method, api_request){ // general purpose function to interact with twitter API // for method and api_request doc see dev.twitter.com/doc/ // retuns object var oauthConfig = UrlFetchApp.addOAuthService("twitter"); oauthConfig.setAccessTokenUrl( "https://api.twitter.com/oauth/access_token"); oauthConfig.setRequestTokenUrl( "https://api.twitter.com/oauth/request_token"); oauthConfig.setAuthorizationUrl( "https://api.twitter.com/oauth/authorize"); oauthConfig.setConsumerKey(getConsumerKey()); oauthConfig.setConsumerSecret(getConsumerSecret()); var requestData = { "method": method, "oAuthServiceName": "twitter", "oAuthUseToken": "always" }; try { var result = UrlFetchApp.fetch( "https://api.twitter.com/1/"+api_request, requestData); var o = Utilities.jsonParse(result.getContentText()); } catch (e) { Logger.log(e); } return o; } function getFriendAndFo(sheetName){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName(sheetName); sheet.getRange(2, 1, sheet.getLastRow(), sheet.getMaxColumns()).clear({contentsOnly:true}); //clear sheet var cursor = "-1"; while(cursor != "none"){ // while twitter returns data loop try { var o = tw_request("GET", "statuses/"+sheetName+".json?cursor="+cursor); // 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"] = "twitter.com/"+data[i].screen_name; } } var headRange = sheet.getRange(1, 1, 1, sheet.getMaxColumns()); var rowIndex = sheet.getLastRow()+1; setRowsData(sheet, data, headRange, rowIndex); // dump data for this loop to sheet if (o.next_cursor!="0"){ cursor = o.next_cursor; // get next cursor } else { cursor = "none"; // break } } catch (e) { Logger.log(e); } } }
Last updated by Martin Hawksey at .
Amazing! saved me a whole lot of time. Thanks!
Jon Thomas (@Story_Jon) You rock! The call back URL was the fix to help me authorize the app.
Hey, did you ever fix so you can download more than 5000 tweets? Mine isn’t working either, but great job making this, tho :)
@Morten it should be able to work with over 5000 but you need to configure the getMoreFriendOrFo() function in the script editor – there’s documentation on my site somewhere ;-s
This is a very helpful tool.
For my study, I need to have not only the friends and followers of a specific screen name but also the ‘friend’ and ‘follower’ connections between those. Does anyone know of a script that will download this type of data from Twitter? I know that Is there a NodeXL provides this option but, unfortunately, it is extremely slow…
Any help or guidance with this will be greatly appreciated.
Thanks.
John
Hi John – unfortunately because of the volume of data required it’s always going to be slow. Tony Hirst has a python script for this soft of thing but he’s whitelisted so can get 10k+ api calls an hour. If you don’t want to leave your PC on all day an alternative might be using scraperwiki https://scraperwiki.com/scrapers/username_twitter_followers_id_manual_row_w_batc_10/
Martin
Hi! When I try to load the Twitter menu, I get an error message Script function onOpen could not be found. Any suggestions? Thanks.
Try making a fresh copy
Yep, did that. More than once. Tried it in IE and Opera using different google accounts and get the same message.
There appeared to be temporary server issues with Apps Script in the last 24 hours
Thanks for this great tool
it really helped me a lot in colecting data. However, I’ve tried get other person follower but the max it could get is 5000 then i tried to do it again for the same person but i couldn’t. Plus, i’m afraid even if it did, it’ll get the same first 5000 again which wont be very helpful for me.
could you plz let me know if there’s another way around it so i can get all the followers of another person
again thank you for this powerful tool
Getting more than 5000 is a pain but possib
twitter google script martin cursor
for its contents. This is a safe-cache copy of the original web site.