如何使用Tweetsharp从Twitter获得国家地点的详细信息?(How to get coun

2019-10-19 10:47发布

谁能帮我用Tweetsharp API从Twitter获得国家信息? 我从一个程序来获取用户的细节写的摘要,但我无法得到用户的国家的细节。

        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 + ",");
        }

Answer 1:

据我所知,你都可以从指定的用户的追随者列表,然后你试图让跟随国家。 你需要为了得到国家信息调用GetUserProfile每个跟随者(如果已经提供)



Answer 2:

你的代码是从一个用户的身份得到国家。 但是从用户的用户“地方”的状态(即位置)内获得地理坐标 ,许多用户选择不共享这些信息。

而不是试图从他们的状态确定用户的位置,我指的是用户的“位置”和“时区”。 然而,作为与用户的“广场”,“位置”和“时区”也是可选的。

这里就是跟随者的用户名,位置和时区的输出,与用户的URL列表以及一个例子(这是又可选!)

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();
}


文章来源: How to get country place details from Twitter using Tweetsharp?