0

我的网络应用程序有 function.php,它在不同的函数中定义了所有 curl api 调用。

我想设置速率限制/回退以防止在我的 Google Drive API v3 调用中出现超出用户速率限制的问题。

functions.php 中的函数示例:

function copyfilefromyou($id, $token, $folder)
{
    $url = "https://www.googleapis.com/drive/v3/files/$id/copy?supportsAllDrives=true&supportsTeamDrives=true";
    $authorization = "Authorization: Bearer $token";
    $data = array(
        "parents" => [["id" => $folder]],
        'description' => 'Copying your file'
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        $authorization
    ));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $result = curl_exec($ch);
    $json = json_decode($result, true);
    curl_close($ch);
    return $json;
}
4

0 回答 0