gpt4 book ai didi

php - cURL 调用 Twitter API session "Rate Limit"而没有发出超过 5 个请求

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:42:54 24 4
gpt4 key购买 nike

我刚刚开始对一个非常非常基本的调用Twitter API (http://api.twitter.com/1/statuses/user_timeline.json) 到通过 cURL 将我的推文拉到我的网站。但是,使用一个页面还没有人知道存在(因此消除了无意中的流量),我之前遇到了 Rate Limit Exceeded 的情况我什至有机会测试它。它说它会在 5 点后重置小时,所以我再次检查,一分钟它可以工作,然后又回来了告诉我我的速率限制已超出。对于了解 Twitter API 和/或 cURL 的人来说,有几个问题:

首先,速率限制是否适用于我的服务器(而不是用户)?我想是的,但是这当然会让事情变得艰难。每位访问者甚至一次 API 调用可以在流量很小的站点上轻松超过速率限制一个小时内。有没有办法将调用与访客关联起来,而不是服务器?似乎可能不是,但我不完全确定整个 API 都有效,并且 cURL 似乎在许多地方。我知道如果我使用 JSON 和 AJAX 中的数据我可以来自用户的那个请求,但只是为了争论,什么关于 cURL?

其次,知道我怎么可能在没有刷新页面?我支付在另一个位置托管的费用,所以我可能与另一个站点共享服务器空间,但我的站点肯定有一个独特的 IP,所以应该……应该可以,对吧?所以怎么回事我什至没有运行代码就超过了速率限制(或者运行一次?)?

以下是我的代码,如果有帮助的话:

$ch=curl_init("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=screenname");
curl_setopt_array($ch,array(
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_TIMEOUT=>5,
)
);
$temp=curl_exec($ch);
curl_close($ch);
$results=json_decode($temp,true);

此外,我现在已经知道,如果 Twitter 返回速率限制错误,它会在文本文件中记录错误,以及限制重置的时间。查看该文件,它唯一一次更新(我没有重写它,它只是添加)是在我加载页面时(可能一小时一次或两次),所以它不像其他东西正在使用此页面并调用此 URL。

有什么帮助吗?

最佳答案

经过身份验证的请求应计入用户每小时 350 次的限制。未经身份验证的请求将计入​​您的 IP 地址每小时 150 次的限制。

如果您在开发过程中遇到限制,Twitter 通常非常愿意将开发服务器 IP 列入白名单。

http://dev.twitter.com/pages/rate-limiting

Some applications find that the default limit proves insufficient. Under such circumstances, we offer whitelisting. It is possible to whitelist both user accounts and IP addresses. Each whitelisted entity, whether an account or IP address, is allowed 20,000 requests per hour. If you are developing an application and would like to be considered for whitelisting you fill out the whitelisting request form. Due to the volume of requests, we cannot respond to them all. If your request has been approved, you'll receive an email.

关于php - cURL 调用 Twitter API session "Rate Limit"而没有发出超过 5 个请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4101877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com