duanba7498 2018-01-21 06:32
浏览 25

Google Drive api upload已超出用户限制

I'm using PHP SDK to copy files to Google Drive, my account can use unlimited storage

After 300-500 files uploaded, User rate limit exceeded show up and i can't upload until next day

{
  "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>";
}

Update using batching request still getting error

$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();
}

In API dashboard the request in 1 hour is 344

enter image description here

  • 写回答

1条回答 默认 最新

  • dpkajqd31574096 2018-01-21 10:48
    关注

    That's happening because you're doing your request probably at a fast rate. I would suggest:

    1. slowing down, like creating a delay in between requests.

    2. If you can perform Batching Requests then do so.

    3. If it applies to you, try using other users to create the request under the project, like sharding the requests,.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)