如何使用Tweetsharp从Twitter获取国家/地区详细信息? [英] How to get country place details from Twitter using Tweetsharp?
问题描述
有人可以使用Tweetsharp API帮助我从Twitter获取国家/地区详细信息吗?我已经从程序中编写了一段代码来获取用户的详细信息,但是我无法获取用户的国家/地区的详细信息.
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 + ",");
}
推荐答案
您的代码正在从用户身份获取国家/地区.但是,从用户地理坐标,许多用户选择不共享此信息.
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.
这是一个示例,其中输出关注者的用户名,位置和时区,以及用户URL列表(这也是可选的!)
Here's an example where follower's username, location and timezone are outputted, along with a list of users URLs (which are again optional!)
static void Main(string[] args)
{
var follwerUrls = new StringBuilder();
var followerNameLocationAndTimeZones = new StringBuilder();
var twitterService = new TwitterService("yourConsumerKey", "yourConsumerSecret");
twitterService.AuthenticateWith("yourToken", "yourTokenSecret");
var userProfile = twitterService.GetUserProfile(new GetUserProfileOptions { IncludeEntities = true, SkipStatus = false });
var followerOptions = new ListFollowersOptions
{
IncludeUserEntities = true,
ScreenName = userProfile.ScreenName,
SkipStatus = false,
UserId = userProfile.Id
};
var usersfollowers = twitterService.ListFollowers(followerOptions);
foreach (var follower in usersfollowers)
{
followerNameLocationAndTimeZones.Append(follower.Name);
followerNameLocationAndTimeZones.Append(", ");
followerNameLocationAndTimeZones.Append(string.IsNullOrEmpty(follower.Location) ? "LOCATION NOT SPECIFIED" : follower.Location);
followerNameLocationAndTimeZones.Append(", ");
followerNameLocationAndTimeZones.Append(string.IsNullOrEmpty(follower.TimeZone) ? "TIMEZONE NOT SPECIFIED" : follower.TimeZone);
followerNameLocationAndTimeZones.Append('\n');
follwerUrls.Append(follower.Url ?? "URL NOT SPECIFIED");
follwerUrls.Append('\n');
}
Console.WriteLine(followerNameLocationAndTimeZones.ToString());
Console.WriteLine(follwerUrls.ToString());
Console.ReadKey();
}
这篇关于如何使用Tweetsharp从Twitter获取国家/地区详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!