Can't get screenName of a list of user ID because of the API rate Limits. What can I do? linqtotwitter c#

妖精的绣舞 提交于 2020-01-15 12:26:07

问题


I have a function in my application that find IDs of a user followers. But I want to get the screenName of these followers.

I tried to get directly followers.screenName but it doesn't work because followers type is SocialGraph and not string! I tried to convert this on string but I can't because it returns a list.

It cause problems for example when I search someone who has 1680 followers. It gives me the error : The rate limit is exceeded.

I want to know if it is possible to do the same thing with a group of userID to not exceed the rate limits of the API? I am working with lintotwitter...

What can I do?

My code is the following:

 public List<string> RecupererFollower()
        {
            List<string> idFollowers=new List<string>();
            var followers =
                (from follower in MainPage.twitterCtxProp.SocialGraph
                 where follower.Type == SocialGraphType.Followers &&
                       follower.ScreenName == MainPage.texte 
                 select follower)
                 .ToList();
            idFollowers = followers[0].IDs;

            return idFollowers;

        }

        public List<User> GetScreenName()
        {
            List<string>idFollowers=RecupererFollower();
            int nbfollower = idFollowers.Count();
            List<User> listeFollowers = new List<User>();


            for (int i = 0; i < nbfollower; i++)
                {
                var usersResponse =
                   (from user in MainPage.twitterCtxProp.User
                    where user.Type == UserType.Lookup &&
                         user.UserID == idFollowers[i]
                    select user).SingleOrDefault();

                Users = new User                                                 //Un utilisateur est créé grâce aux données récupérées précédemment.

               {
                   Name = usersResponse.ScreenName,
                   Text = usersResponse.Status.Text,
                   ImageUrl = usersResponse.ProfileImageUrl,
                   Bio = usersResponse.Description,
                   Url = usersResponse.Url,
                   NbFollowers = usersResponse.FollowersCount,
                   NbFavorite = usersResponse.FavoritesCount,
                   NbStatus = usersResponse.StatusesCount,
                   NbFollowing = usersResponse.FriendsCount,
                   NbListe = usersResponse.ListedCount,
                   Timezone = usersResponse.TimeZone,
                   Location = usersResponse.Location,
               };
                listeFollowers.Add(Users);
                }
            return listeFollowers;
        }

回答1:


The Twitter API is setting rate limits. The limit is a certain number of requests during a time window. The time window is typically 15 minutes. For Lookup, the rate limit is 180. You can use a HelpType.RateLimits query: http://linqtotwitter.codeplex.com/wikipage?title=Getting%20Rate%20Limits - this will let you write code to figure out what a rate limit is. Then, you can max out your rate limit and wait until the next window to continue.



来源:https://stackoverflow.com/questions/15221534/cant-get-screenname-of-a-list-of-user-id-because-of-the-api-rate-limits-what-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!