The Twitter limits the queries?

Jun 30, 2009 at 9:41 PM
I'm using LinqtoTwitter to see who I'm following. But he is not bringing all the people? What is happening?
Thanks
Ramon



Coordinator
Jun 30, 2009 at 9:50 PM

According to the Twitter API (http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0friends), they only return 100 at a time. Are you following over 100 people?  If so, you can set the Page property, in the where clause, and loop through pages until your query doesn't return anymore values.

Joe

Jun 30, 2009 at 10:27 PM
Edited Jul 1, 2009 at 6:20 PM

Yes.

In the query below  tweet has no property Page. Correct?
[],
tks


var users =
                  from tweet in twitterCtx.User
                  where tweet.Type == UserType.Followers &&
                        tweet.ID == twitterCtx.UserName   &&
                       tweet.Page= ??                    
                  select tweet

Jul 28, 2009 at 11:06 AM

Hey Joe,

Any answer regarding the latest question here? it seems that Page is only avaiable for SocialGraph table and not for the User table. Moreover, it seems that the SocialGraph.Page is redundent (I get all my 2000 without paging).

Thanks,

Gilad

Coordinator
Jul 28, 2009 at 12:40 PM

ramonduraes,

I think this ChangeSet, or later, solves paging problems with User queries:

http://linqtotwitter.codeplex.com/SourceControl/changeset/view/57111

Joe

Coordinator
Jul 28, 2009 at 12:45 PM

giladkhen,

I'll take a look at SocialGraph paging.

Joe

Coordinator
Jul 28, 2009 at 12:57 PM

giladkhen,

I just looked at the Twitter API spec and they say that the page size for SocialGraph is 5000 (http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-followers%C2%A0ids). This is a parameter you can't set. However, examining the impact, what you're getting back is only IDs.  Now that paging is working with User queries, will that work for you?

Joe

Jul 28, 2009 at 1:49 PM

Joe,

Thanks for your propt reply!

> "Now that paging is working with User queries"

am I missing something? as far as I can tell ramonduraes's post above is correct - there is no Page propert for User table in V1.11, only for SocialGraph table. If there was - it would help, yes.

At the current state is I cannot see any way to retrieve more than 100 FRIST friends except for the socialgraph - which insufficient as you only get IDs. If there is one - could you provide a quick code sample?

Thanks,

G.

Coordinator
Jul 28, 2009 at 6:04 PM

G,

You can download the latest ChangeSet, which does have a Page property for User queries. I also added a GetFollowersDemo method to show how it works.

Joe

Mar 24, 2010 at 8:39 PM
Edited Mar 24, 2010 at 9:04 PM

I'm going like this:

private List<User> GetFollowers(string userID)
        {
            var users = from tweep in _mainManager.GetTwitterContext().User
                        where tweep.Type == UserType.Followers &&
                              tweep.ID == userID &&
                              tweep.Page == 1
                        select tweep;
            List<User> result = users.ToList();
            var users2 = from tweep in _mainManager.GetTwitterContext().User
                         where tweep.Type == UserType.Followers &&
                              tweep.ID == userID &&
                              tweep.Page == 2
                        select tweep;
            result.AddRange(users2.ToList());
            return result;
        }

And function returns only first hundred of users but twice. Though I have 116 followers. Is there an error in my code or a bug in LinqToTwitter?

Coordinator
Mar 26, 2010 at 3:45 AM
Edited Mar 26, 2010 at 3:46 AM

Hi Maxthegreatest,

The Page parameter is deprecated for certian User queries in Twitter, they just ignore it now. So, what you're seeing is the results as if you didn't use Page, which returns the first 100 users.  Instead, you should use cursors.  Here's an example:

        private static void UserFollowersQueryDemo(TwitterContext twitterCtx)
        {
            int pageNumber = 1;
            string nextCursor = "-1";
            while (!string.IsNullOrEmpty(nextCursor) && nextCursor != "0")
            {
                var users =
                    (from user in twitterCtx.User
                     where user.Type == UserType.Followers &&
                           user.ID == "15411837" &&
                           user.Cursor == nextCursor
                     select user)
                     .ToList();

                Console.WriteLine(
                    "Page #" + pageNumber + " has " + users.Count + " users.");

                nextCursor = users[0].CursorMovement.Next;
                pageNumber++;
            }
        }

 
Notice that I have a CursorMovement property on the User entity to help manage Previous and Next cursors. You start it off by setting the Cursor property of the user range variable to -1. Then use the Next property of CursorMovement to get the next set of results.  Every CursorMovement is the same, so you only need to look at the first one.

Joe

Mar 26, 2010 at 7:16 PM

Thnx for help. It's working:)