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 http://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"] = "http://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 at .

Loading...

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 possible. The answer is in this comment thread ;)
amazing work
Hi,
I was confused about how to get other kind of data like the other column headers you mentioned. tried changing values in the sheet but got empty results.. so how exactly can one add other columns for the other values?
Hi Luis – was there a particular column you were trying to add?
Thank you for this!!!
Help, please. I need to use one of the advanced options but I’m not sure if I’m doing this correctly. I created a new column in the Followers sheet and named the header status_in_reply_to_screen_name . Am I missing something? Cos this method is not working for me.
Hi :). Is there a way to run the script again and only add new additions? Rather than adding the entire list again and having duplicates?
Thank you by the way this has already saved me a TON of hours!
Hello, gone through the post and still didn’t see a means of extracting just my followers list. Anyhow anyone can help with that for me? Thanks
Hi Martin – a question for you a bit off topic here. Twitter’s data column gives a date/time value. Do you know of any easy way to convert that (from Excel) to a time interval such that it can be used for dynamic analysis?
Many thanks,
Charlton
Such a shame they made you remove this sir – used to be an excellent tool!!
Hi Martin, your script is awesome and I got it working in the end, but with a little glitch. I suggest you amend the instructions:
Step 4.5 While in the Script Editor mode, select Run > authenticate
Step 6.5 Back in the excel file select Twitter > Test Connection – you should get back a message stating “Connected to Twitter Successfully”. If you do not get this message, check to make sure you have the call-back URL filled in on our Twitter App Settings – make your call-back URL the same as your website URL even if its a fictitious one for the time being
Thank you! I’m also searching for a way to get emails of all my twitter followers. I can create a new landing page, but it will be much time consuming.
Well thanks!
Hi Martin
Following your instructions but the twitter dev site won’t accept – Callback URL = https://spreadsheets.google.com/macros as a valid URL, what am I doing wrong please?#
thx
Dave
Just tried myself and it worked fine. Only thing I can think of is whitespace around the url (https://spreadsheets.google.com/macros)
I keep getting a
APPS Script
OOPs it didn’t work message
any ideas?
If the user has more than 100k follower, how to get only the first 5000 follower ?
Got some difficulties (wanted to go too fast…) but coming back to the tutorial everything is well documented.
Did not work in Opera, worked fine in Chrome.
Awesome result.
Thanks Martin !
I have made a facebook of all my followers, based on this script.
How I did it: http://www.trendmatcher.nl/2013/05/wie-volgen-mij-nu-eigenlijk.html
(sorry, in Dutch:-)
Here is the facebook:
http://www.karssenberg.nl/volgenmij.html
Thanks for your great scripts!
Amazing script! This is exactly what I was looking for. Thank you for putting it together. Love the ability to add columns.
Works great, but how do I add more column headers?
I cannot figure thet out
Sorry, found the answer in the comments already!
Request failed for returned code 410. Server response: {“errors”: [{"message": "The Twitter REST API v1 will soon stop functioning. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]} (line 585, file “Twitter Script”)
I am getting an 410 error when running the Authenticate function
Request failed for returned code 410. Server response: {“errors”: [{"message": "The Twitter REST API v1 will soon stop functioning. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]} (line 585, file “Twitter Script”)
Same, Stefan…
The spreadsheet has not retrieved any followers since the migration to the API 1.1. Will an updated version that interacts with the new API be available at some point?
Thanks a lot for this, it is a great tool!
I fixed it – go to script editor and “find” all instances of “/1/” (there should be 2) and “replace” with “1.1″. Tada!!!
jules:)