Below are some bits of the code used in the spreadsheet, to fetch twitter followers list.
function tw_request(method, api_request){
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});
var cursor = "-1";
while(cursor != "none"){
try {
var o = tw_request("GET", "statuses/"+sheetName+".json?cursor="+cursor);
var data = o.users;
for (i in data){
if (data[i].status){
for (j in data[i].status){
data[i]["status_"+j] = data[i].status[j];
}
}
if (data[i].screen_name){
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);
if (o.next_cursor!="0"){
cursor = o.next_cursor;
} else {
cursor = "none";
}
} catch (e) {
Logger.log(e);
}
}