首页 > 解决方案 > 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();

标签: phpcurl

解决方案


如果你查看你的速率限制,你会看到你是否达到了限制

$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,并且已经超出了限制,现在似乎已被重置。


推荐阅读