【发布时间】:2019-09-08 06:12:03
【问题描述】:
我目前正在查看 TweetInvi 的文档,并查看了 RateLimit 类。
而且我一直在尝试实现它,我不知道这是对 Twitter 缺乏了解还是限制,但我似乎无法找到一种方法来发送 notification 在控制台消息方面说“嘿,你已经达到了每小时的限制,它将在 x 分钟内重置……”或类似的内容。
我正在查看此示例,您也可以在文档中找到该示例。
TweetinviEvents.QueryBeforeExecute += (sender, args) =>
{
var queryRateLimits = RateLimit.GetQueryRateLimit(args.QueryURL);
// Some methods are not RateLimited. Invoking such a method will result in the queryRateLimits to be null
if (queryRateLimits != null)
{
if (queryRateLimits.Remaining > 0)
{
// We have enough resource to execute the query
return;
}
// Strategy #1 : Wait for RateLimits to be available
Console.WriteLine("Waiting for RateLimits until : {0}", queryRateLimits.ResetDateTime.ToLongTimeString());
Thread.Sleep((int)queryRateLimits.ResetDateTimeInMilliseconds);
// Strategy #2 : Use different credentials
var alternateCredentials = TwitterCredentials.CreateCredentials("", "", "", "");
var twitterQuery = args.TwitterQuery;
twitterQuery.OAuthCredentials = alternateCredentials;
// Strategy #3 : Cancel Query
args.Cancel = true;
// Strategy #4 : Implement yours!
}
};
当我尝试发送一条推文说“嘿,慢点,伙计,你已经达到极限,请稍等(剩下的时间) )"
如果这个包装器甚至可以做到的话。
【问题讨论】: