Can anyone help me to get country details from Twitter using the Tweetsharp API? I have written a snippet from a program to get the details of the user, but I am unable to get the country details of the user.
string tweetText = string.Empty;
int count;
StringBuilder sbWebsite = new StringBuilder();
StringBuilder sbCountry = new StringBuilder();
TwitterTest obj = new TwitterTest();
TwitterService twitterService = obj.GetAuthentication();
TwitterUser objUser = twitterService.GetUserProfile(new GetUserProfileOptions { IncludeEntities = true, SkipStatus = false });
ListFollowersOptions objFollowerOptions = new ListFollowersOptions();
objFollowerOptions.UserId = objUser.Id;
objFollowerOptions.ScreenName = objUser.ScreenName;
objFollowerOptions.IncludeUserEntities = true;
objFollowerOptions.SkipStatus = false;
objFollowerOptions.Cursor = -1;
TwitterCursorList<TwitterUser> followers = twitterService.ListFollowers(objFollowerOptions);
for (int i = 0; i < followers.Count; i++)
{
if (followers[i].Status != null)
{
if (followers[i].Status.Place != null)
{
if (followers[i].Status.Place.Country != null)
sbCountry.Append(followers[i].Status.Place.Country + ",");
}
}
sbWebsite.Append(followers[i].Url + ",");
}
As far as I can tell, you are getting list of followers from a specified user and then you try to get follower countries. You need to call GetUserProfile for each follower in order to get country information (if one is provided)
Your code is getting the country from a user's status. However a users "Place" within the status (i.e. location) is obtained from a users geo coordinates, and many users choose not to share this information.
Instead of trying to determine a user's location from their status, I'd refer to a Users "Location" and "Timezone". However, as with a users "Place", the "Location" and "Timezone" are also optional.
Here's an example where follower's username, location and timezone are outputted, along with a list of users URLs (which are again optional!)