Search code examples
c#twitterlinq-to-twitter

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


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

Solution

  • 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.