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 ***
Update: added the ability to download other peoples friends/followers
Update 2: added an additional function to use if you have a lot of friends/followers to import. More information about this here.
Benefits of using Google Spreadsheet
- Control – You register for your own API key with Twitter so you have full control of the account
- Automatic whitelisting – Twitter currently automatically whitelist applications built in Google Spreadsheets this means instead of 150 API request per hour you get 20,000 meaning you can export a lot
- 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);
}
}
}
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