Pinterest API如下: 限制每个用户访问令牌每小时1000次点击 https://api.pinterest.com/v1/me/following/users/?access_token=XXXXXXXX&user=XXXXXXX
+-------------+---------------------+------------------+
| userId | usertoFollowPerHour | maxUserAvailable |
+-------------+---------------------+------------------+
| 1 | 100 | 1000|
| 2 | 200 | 9000|
| 3 | 210 | 100|
| 4 | 300 | 1100|
| 5 | 300 | 900|
| . | | |
| . | | |
| . | | |
| n | n| n|
+-------------+---------------------+------------------+
现在我必须关注特定用户ID的用户,以便: 我可以在限制范围内关注用户 Pinterest不会阻止我的个人资料
目前,我这样做是: 每隔3小时就会命中以下函数的URL的cron 功能是:
计算用户在一个循环中跟随Eg:
1. let currentTime = 1:00
and endTime = 2:00
user to follow = 300
timeRemaining = currentTime-endTime => 60 minutes
300/60 = 5 => ceil(5)=5
2. it will fetch five user in one iteration from Pinterest
3. than it will follow them one by one in second loop
4. after that again it will calculate until userToFllow become 0
300-5=295 => ceil(295/timeRemaining(let 59)) = 5
5. again 1 for next user
根据上述逻辑,我们的一些用户被禁止/阻止可能是由于Pinterest reason
如果可能,请建议我使用解决方案回答,是否应该使用多线程或更多功能来执行此异步。如果只能由CodeIgniter完成,我会很高兴
答案 0 :(得分:1)
So the follow this logic in your api:
Each app (with a unique app ID) is allowed 1000 calls per hour for each unique user token. The 60-minute window is a sliding window based on when you make your first request. If you hit your rate limit, you’ll only have to wait a max of 1 hour to get a few more requests.
Every API response returns a header that gives you an update about rate limiting. X-Ratelimit-Limit is the rate limit for that specific request, and X-Ratelimit-Remaining is the number of requests you have left in the 60-minute window.
X-Ratelimit-Limit: 1000
X-Ratelimit-Remaining: 890
Add this condition in your api response header and checking how many remaining .
If you exceed your rate limit for a given endpoint, you’ll get a 429 “Too many requests” error code.
Check for this condition response and trigger email to yourself if the http Code is 429 or log into the log file.
PS: Did not try this but sure it will help you to solve your problem in same way.
答案 1 :(得分:0)
我通过在两个关注API调用之间为同一用户的Pinterest帐户添加 delay 解决了上述帐户禁止问题:
一分钟之内有五个跟随这样
队列:A1,A1,A2,A3,A1
A1-A1-A2-A3-A1-----------------------wait till the end of the minute-------
现在
队列:A1,A1,A2,A3,A1
A1-A2-A3---------A1-----------A1-----wait till the end of the minute-------
A 代表帐户
- 代表秒数
这只是避免禁令的基本实施概述。