Paging thru Followers and Following

Oct 17, 2012 at 5:23 AM
Edited Oct 17, 2012 at 5:25 AM

How do i page thru list of followers and following, instead of fetching the entire list at the same time? Can you quote an example please?

Coordinator
Oct 18, 2012 at 12:23 PM

Hi,

Paging for SocialGraph (followers/following) is managed via a cursor, which is an opaque holder for previous and next pages. The following example is in the downloadable source code:

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

Joe