Fetching All Followers

Feb 26, 2013 at 1:59 PM
I am using the following query to fetch the followers
var queryResponse = from follower in pubTweetCtx.SocialGraph
                                        where follower.Type == SocialGraphType.Followers && follower.UserID == User_ID
                                        select follower;
But it is only returning maximum 5000 follower IDs. How do i get all follower IDs? In my case there are 1 lakh followers or even more.
Coordinator
Feb 26, 2013 at 3:28 PM
Hi,

The max page size is 5000 and you are only getting the first page. SocialGraph uses cursors to page through results. There's a demo in the downloadable source code that shows how to use cursors. Here's an example:
        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++;
            }
        }
@JoeMayo
Feb 27, 2013 at 5:56 AM
It works. But now the problem is, after getting a few pages, Twitter returns "Error while querying twitter". Is that because of Rate limit. If yes then how do I handle it?


From: [email removed]
To: [email removed]
Date: Tue, 26 Feb 2013 07:28:49 -0800
Subject: Re: Fetching All Followers [LinqToTwitter:434546]

From: JoeMayo
Hi,

The max page size is 5000 and you are only getting the first page. SocialGraph uses cursors to page through results. There's a demo in the downloadable source code that shows how to use cursors. Here's an example:
        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++;
            }
        }
@JoeMayo
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
Mar 3, 2013 at 4:10 PM
It looks like the rate limit for followers/ids is 15 calls per 15 minutes. Doesn't sound like that's what you're doing unless "a few" is > 15.