Google Drive api upload已超出用户限制

时间:2018-01-21 06:32:52

标签: php google-drive-api google-php-sdk

我正在使用PHP SDK将文件复制到 Google云端硬盘,我的帐户可以使用无限存储空间

上传300-500个文件后,超出用户速率限制显示,我无法上传到第二天

{
  "code": 403,
  "message": "User rate limit exceeded."
}

function copydrive($driveid,$folder,$newname){
    $fileMetadata = new Google_Service_Drive_DriveFile(array(
        'name' => $newname,
        'parents' => array($folder)
    ));
    $result = $GLOBALS['service']->files->copy($driveid, $fileMetadata);
    return $result->id;
}
$newid = copydrive($episode['drive'],$folderid,$filename);
if($newid!=''){
    $qrun2=$conn->prepare("update episode set mydrive='".$newid."' where id=".$episode['id']);
    $qrun2->execute();
    echo "<script language='javascript'>";
    echo 'setTimeout(function(){window.location.reload(1);}, 2000);';
    echo "</script>";
}
使用批处理请求仍然收到错误

更新

$qrun=$conn->prepare("SELECT * FROM episode WHERE drive!='' and mydrive is null limit 50");
$qrun->execute();
$episode=$qrun->fetchAll();
$batch = $service->createBatch();
$num=0;
foreach($episode as $item){
    $fileMetadata = new Google_Service_Drive_DriveFile(array(
        'parents' => array('parent folder id')
    ));
    $result = $GLOBALS['service']->files->copy($item['drive'], $fileMetadata);
    $batch->add($result,'copy-'.$num);
    $num++;
}
$results = $batch->execute();
$total_rs = count($results);
for($x=0;$x<$total_rs;$x++){
    $qrun2=$conn->prepare("update episode set mydrive='".$results['response-copy-'.$x]->id."' where id=".$episode[$x]['id']);
    $qrun2->execute();
}

在API仪表板中,1小时内的请求为344

enter image description here

1 个答案:

答案 0 :(得分:1)

这种情况正在发生,因为您可能会以很快的速度处理您的请求。我建议:

  1. 放慢速度,就像在请求之间创建延迟一样。

  2. 如果您可以执行Batching Requests,请执行此操作。

  3. 如果它适用于您,请尝试使用其他用户在项目下创建请求,例如分片请求。

相关问题