Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I need to download the list of followers of a list of twitter users for my research. I am using c# code and I have visited the https://dev.twitter.com/console[^] which has as API to extract the associated number to each follower but not the exact Twitter ID which I require. Is there any one to help me
best regards
HDolat
Posted
Updated 12-Mar-12 18:29pm
v2
Comments
Prasad_Kulkarni 13-Mar-12 0:29am    
links formatted

Below are some bits of the code used in the spreadsheet, to fetch twitter followers list.

JavaScript
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);
    }
  }
 
Share this answer
 
Ops, I red it several times but there are many question marks rotaiting above my head. Actually I am looking for an easy API which may help me to convert the User IDs to the screen names.
by the way thanks for the codes
 
Share this answer
 
Comments
Sandeep Mewara 29-Apr-12 13:32pm    
Not an answer. If this was to be a comment to some reply, use ' Have a question or comment' link instead of posting it as a solution.
I did some think which is useful! first of all I used the http://api.twitter.com/1/followers/ids.json?screen_name=username[^]to find the follower users of the username above. then used https://api.twitter.com/1/users/show.json?user_id=the users Id&include_entities=true[^] whicch has the screen name inside. It can be used to download tweets by http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=screen name&count=100&page=1[^] to download tweets
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900