Twitter Rate Limits

Oct 14, 2012 at 4:49 PM

How do I handle Twitter rate limits using LINQToTwitter?

Coordinator
Oct 14, 2012 at 4:56 PM

Hi,

You can use a Help/Ratelimits query.  Here's an example:

            var helpResult =
                (from help in twitterCtx.Help
                 where help.Type == HelpType.RateLimits //&&
                       //help.Resources == "search,users"
                 select help)
                .SingleOrDefault();

            foreach (var category in helpResult.RateLimits)
            {
                Console.WriteLine("\nCategory: {0}", category.Key);

                foreach (var limit in category.Value)
                {
                    Console.WriteLine(
                        "\n  Resource: {0}\n    Remaining: {1}\n    Reset: {2}\n    Limit: {3}",
                        limit.Resource, limit.Remaining, limit.Reset, limit.Limit);
                }
            }

@JoeMayo

Oct 14, 2012 at 5:16 PM
Should I use this query to perform a check on rate limit, before other queries, like, query for getting tweets.



From: [email removed]
To: [email removed]
Date: Sun, 14 Oct 2012 09:57:04 -0700
Subject: Re: Twitter Rate Limits [LinqToTwitter:399298]

From: JoeMayo
Hi,
You can use a Help/Ratelimits query. Here's an example:
            var helpResult =
                (from help in twitterCtx.Help
                 where help.Type == HelpType.RateLimits //&&
                       //help.Resources == "search,users"
                 select help)
                .SingleOrDefault();

            foreach (var category in helpResult.RateLimits)
            {
                Console.WriteLine("\nCategory: {0}", category.Key);

                foreach (var limit in category.Value)
                {
                    Console.WriteLine(
                        "\n  Resource: {0}\n    Remaining: {1}\n    Reset: {2}\n    Limit: {3}",
                        limit.Resource, limit.Remaining, limit.Reset, limit.Limit);
                }
            }

@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
Coordinator
Oct 14, 2012 at 7:27 PM

The timing of when you call and how you use it would depend on your application. Here's some information on how Twitter is handling rate limits now:

The API:

https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status

More guidance on Rate Limiting in v1.1:

https://dev.twitter.com/docs/rate-limiting/1.1

Joe

Oct 16, 2012 at 6:02 AM
Do I need a authenticated twitter context to use the below mentioned query.


From: [email removed]
To: [email removed]
Date: Sun, 14 Oct 2012 09:57:04 -0700
Subject: Re: Twitter Rate Limits [LinqToTwitter:399298]

From: JoeMayo
Hi,
You can use a Help/Ratelimits query. Here's an example:
            var helpResult =
                (from help in twitterCtx.Help
                 where help.Type == HelpType.RateLimits //&&
                       //help.Resources == "search,users"
                 select help)
                .SingleOrDefault();

            foreach (var category in helpResult.RateLimits)
            {
                Console.WriteLine("\nCategory: {0}", category.Key);

                foreach (var limit in category.Value)
                {
                    Console.WriteLine(
                        "\n  Resource: {0}\n    Remaining: {1}\n    Reset: {2}\n    Limit: {3}",
                        limit.Resource, limit.Remaining, limit.Reset, limit.Limit);
                }
            }

@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
Coordinator
Oct 16, 2012 at 8:44 PM

You're correct.  All Twitter API v1.1 calls require authentication. Sincle LINQ to Twitter has been upgraded to Twitter API v1.1, you would need to authenticate.

Joe

Oct 17, 2012 at 4:44 AM
I can fetch public tweets just thru API key and API Secret Key. I don't need to go thru the entire OAuth process. So, for Rate Limit query do I have to go thru the entire oAuth process or just API key and API Secret key woud do?


From: [email removed]
To: [email removed]
Date: Tue, 16 Oct 2012 13:44:57 -0700
Subject: Re: Twitter Rate Limits [LinqToTwitter:399298]

From: JoeMayo
You're correct. All Twitter API v1.1 calls require authentication. Sincle LINQ to Twitter has been upgraded to Twitter API v1.1, you would need to authenticate.
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
Coordinator
Oct 18, 2012 at 12:18 PM

That's right. Since credentials don't expire, you can continue reusing them. That means one person will only ever have to go through the authentication process one time.

Joe

Feb 27, 2013 at 6:04 AM

I tried using the query below, but I don't get the option HelpType.RateLimits

From: [email removed]
To: [email removed]
Date: Sun, 14 Oct 2012 09:57:04 -0700
Subject: Re: Twitter Rate Limits [LinqToTwitter:399298]

From: JoeMayo
Hi,
You can use a Help/Ratelimits query. Here's an example:
            var helpResult =
                (from help in twitterCtx.Help
                 where help.Type == HelpType.RateLimits //&&
                       //help.Resources == "search,users"
                 select help)
                .SingleOrDefault();

            foreach (var category in helpResult.RateLimits)
            {
                Console.WriteLine("\nCategory: {0}", category.Key);

                foreach (var limit in category.Value)
                {
                    Console.WriteLine(
                        "\n  Resource: {0}\n    Remaining: {1}\n    Reset: {2}\n    Limit: {3}",
                        limit.Resource, limit.Remaining, limit.Reset, limit.Limit);
                }
            }

@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 3:01 PM
A neat thing that I didn't notice right away is that every time you call the REST API, rate limiting information for the endpoint you just called is returned in the header of the response. That stuff is in context.RateLimitReset, context.RateLimitRemaining and context.RateLimitCurrent.
Mar 4, 2013 at 8:21 AM
Thanks shibumi. I will look it up.


From: [email removed]
To: [email removed]
Date: Sun, 3 Mar 2013 08:01:28 -0800
Subject: Re: Twitter Rate Limits [LinqToTwitter:399298]

From: shibumi
A neat thing that I didn't notice right away is that every time you call the REST API, rate limiting information for the endpoint you just called is returned in the header of the response. That stuff is in context.RateLimitReset, context.RateLimitRemaining and context.RateLimitCurrent.
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
Apr 3, 2013 at 6:24 AM
I used the twittercontext.ratelimitremaining, twittercontext.ratelimitcurrent. But they are always -1. Arent they suppose to update with every request to twitter.