Only 5000 coming back out of 40000

Sep 4, 2012 at 5:55 AM

 

 

 

 

This query only returns 5000 records. Does the underlying twitter api allow me to get 5000 to 10000?

 What would the linq query look like?

 

     var socialGraphResponse =
        (from follower in twitterCtx.SocialGraph
         where follower.Type == SocialGraphType.Followers &&
               follower.ScreenName == "MSCloud"
         select follower).Single();

Any help appreciated.

Bruno 

 

 

 

Coordinator
Sep 4, 2012 at 6:22 AM

Hi Bruno,

The social graph uses a Cursor, which is an opaque identifier to specify moving to previous and next pages. Here's a snippet that shows how it works:

        private static void ShowFollowersWithCursorDemo(TwitterContext twitterCtx)
        {
            int pageNumber = 1;

            // "-1" means to begin on the first page
            string nextCursor = "-1";

            // cursor will be "0" when no more pages
            // notice that I'm checking for null/empty - don't trust data
            while (!string.IsNullOrEmpty(nextCursor) && nextCursor != "0")
            {
                var followers =
                    (from follower in twitterCtx.SocialGraph
                     where follower.Type == SocialGraphType.Followers &&
                           follower.UserID == 15411837ul &&
                           follower.Cursor == nextCursor // <-- set this to use cursors
                     select follower)
                    .FirstOrDefault();

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

                // use the cursor for the next page
                // this is not a page number, but a marker (cursor)
                // to tell Twitter which page to return
                nextCursor = followers.CursorMovement.Next;
                pageNumber++;
            }
        }



This sample is also available in the demos included in the downloadable code.

Joe

Coordinator
Sep 4, 2012 at 6:28 AM

Just another quick note. Limit-wise, with a lot of followers, you might want to watch rate limits, available through properties of the TwitterContext instance and updated after every query. If you start exceeding rate limits, you might want to pace your queries until you get all followers.

Since I don't have that many followers myself, the scenario is a little tough for me to test, but feedback is welcome on anything that doesn't look right. :)

Joe.

Sep 4, 2012 at 8:54 AM
Excellent and timely response. Thank you!

Bruno Terkaly Novato, Ca brunoterkaly@hotmail.com


From: [email removed]
To: [email removed]
Date: Mon, 3 Sep 2012 23:22:57 -0700
Subject: Re: Only 5000 coming back out of 40000 [LinqToTwitter:394304]

From: JoeMayo
Hi Bruno,
The social graph uses a Cursor, which is an opaque identifier to specify moving to previous and next pages. Here's a snippet that shows how it works:
        private static void ShowFollowersWithCursorDemo(TwitterContext twitterCtx)
        {
            int pageNumber = 1;

            // "-1" means to begin on the first page
            string nextCursor = "-1";

            // cursor will be "0" when no more pages
            // notice that I'm checking for null/empty - don't trust data
            while (!string.IsNullOrEmpty(nextCursor) && nextCursor != "0")
            {
                var followers =
                    (from follower in twitterCtx.SocialGraph
                     where follower.Type == SocialGraphType.Followers &&
                           follower.UserID == 15411837ul &&
                           follower.Cursor == nextCursor // <-- set this to use cursors
                     select follower)
                    .FirstOrDefault();

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

                // use the cursor for the next page
                // this is not a page number, but a marker (cursor)
                // to tell Twitter which page to return
                nextCursor = followers.CursorMovement.Next;
                pageNumber++;
            }
        }


This sample is also available in the demos included in the downloadable code.
Joe
Read the full discussion online.
To add a post to this discussion, reply to this email (LinqToTwitter@discussions.codeplex.com)
To start a new discussion for this project, email LinqToTwitter@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com