php - PHP CURL 库给出类型为“invalid_access_error”的错误“超出速率限制”
问题描述
我正在尝试通过 PHP CURL 库调用 API。但每次我打电话时都会出现这个错误。
Array (
[error] => Array (
[type] => invalid_access_error
[message] => Rate limit exceeded
)
)
$curl = curl_init();
//$result=$this->cronjob_model->get_new_appoiment();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.dentally.co/v1/appointments/1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer 2549fc0ac144797a850a9583e3f685d06b830fd6cc17d8dfe4867fce82adb6bc"
),
));
$result = curl_exec($curl);
$someArray=json_decode($result, true);
print_r($someArray);
die();
解决方案
如果你查看你的速率限制,你会看到你是否达到了限制
$curl = curl_init();
//$result=$this->cronjob_model->get_new_appoiment();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.dentally.co/rate_limit",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer 2549fc0ac144797a850a9583e3f685d06b830fd6cc17d8dfe4867fce82adb6bc"
),
));
$result = curl_exec($curl);
$someArray=json_decode($result, true);
print_r($someArray);
Array
(
[resources] => Array
(
[core] => Array
(
[limit] => 3600
[remaining] => 3422
[reset] => 1615456800
)
[appointment_availability] => Array
(
[limit] => 200
[remaining] => 200
[reset] => 1615456800
)
[sms] => Array
(
[limit] => 300
[remaining] => 300
[reset] => 1615507200
)
)
)
我猜在测试时您经常调用 API,并且已经超出了限制,现在似乎已被重置。
推荐阅读
- python - New Twitch API getting json data Python 3
- azure-devops - Azure Pipelines: How to have a permission limited resource let forks pass without access?
- c++ - How to declare STL style C++ hash map iterator?
- php - Google.visualization.dashboard not rendering with json array php
- spring - 尾随 lambda 的上下文
- django - 由于包含“!”而导致的 Django SECRET_KEY 错误 在秘钥中
- sql-server - 无法将数据库架构复制到另一个 SQL Server 实例
- redis - 如何从 rq 中排队的函数获取返回值?
- system-verilog - always_ff 或 always_comb 用于在简单的 TestBench 中生成时钟
- spring-boot - 使用 Apigee 和 Okta 的 Spring Boot