Skip to content

Instantly share code, notes, and snippets.

@shime
Forked from anonymous/twitterservice code
Created May 23, 2012 14:36
Show Gist options
  • Save shime/2775560 to your computer and use it in GitHub Desktop.
Save shime/2775560 to your computer and use it in GitHub Desktop.
twitterservice code
/// <summary>
/// Dohvaća pratitelje trenutnog korisnika
/// </summary>
/// <param name="AccessToken">
/// Access token povezan sa računom trenutnog korisnika
/// </param>
/// <returns>Lista profila pratitelja trenutnog korisnika</returns>
public static List<TwitterUserProfile> GetFollowers(TwitterTokens AccessToken)
{
TwitterResponse<UserIdCollection> followersResponse =
TwitterFriendship.FollowersIds(
convertTwitterToOAuthToken(AccessToken));
if (followersResponse.Result == RequestResult.Success)
{
List<TwitterUserProfile> followers = new List<TwitterUserProfile>();
LookupUsersOptions lookupOptions = new LookupUsersOptions();
// Loop through all of the follower user ids
for (int index = 0;
index < followersResponse.ResponseObject.Count;
index++)
{
// We can only look up 100 users at a time
if ((index % 100 == 0)&&(index!=0))
{
getAndConvertPartialUserList(AccessToken,
followers, lookupOptions);
// Clear the lookup user ids
lookupOptions.UserIds.Clear();
}
lookupOptions.UserIds.Add(
followersResponse.ResponseObject[index]);
}
if (lookupOptions.UserIds.Count>0)
getAndConvertPartialUserList(AccessToken,
followers, lookupOptions);
return followers;
}
else
{
throw new Exception(followersResponse.ErrorMessage);
}
}
private static void getAndConvertPartialUserList(
TwitterTokens AccessToken,
List<TwitterUserProfile> followers,
LookupUsersOptions lookupOptions)
{
TwitterResponse<TwitterUserCollection> userLookupResponse =
TwitterUser.Lookup(
convertTwitterToOAuthToken(AccessToken),
lookupOptions);
if (userLookupResponse.Result == RequestResult.Success)
{
foreach (TwitterUser user in userLookupResponse.ResponseObject)
{
followers.Add(new TwitterUserProfile()
{
Description = user.Description,
Id = user.Id,
Language = user.Language,
Location = user.Location,
Name = user.Name,
NumberOfFriends = user.NumberOfFriends,
NumberOfStatuses = user.NumberOfStatuses,
ProfileImageLocation = user.ProfileImageLocation,
ProfileSecureImageLocation = user.ProfileImageSecureLocation,
ScreenName = user.ScreenName,
Status = user.Status.Text,
Website = user.Website
});
}
}
}
public class TwitterUserProfile
{
private string description;
public string Description
{
get { return description; }
set { description = value; }
}
private decimal id;
public decimal Id
{
get { return id; }
set { id = value; }
}
private string language;
public string Language
{
get { return language; }
set { language = value; }
}
private string location;
public string Location
{
get { return location; }
set { location = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private long numberOfFriends;
public long NumberOfFriends
{
get { return numberOfFriends; }
set { numberOfFriends = value; }
}
private long numberOfStatuses;
public long NumberOfStatuses
{
get { return numberOfStatuses; }
set { numberOfStatuses = value; }
}
private string profileImageLocation;
public string ProfileImageLocation
{
get { return profileImageLocation; }
set { profileImageLocation = value; }
}
private string profileSecureImageLocation;
public string ProfileSecureImageLocation
{
get { return profileSecureImageLocation; }
set { profileSecureImageLocation = value; }
}
private string status;
public string Status
{
get { return status; }
set { status = value; }
}
private string screenName;
public string ScreenName
{
get { return screenName; }
set { screenName = value; }
}
private string website;
public string Website
{
get { return website; }
set { website = value; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment