首页 > 解决方案 > 使用 google drive api v3 复制文件返回“提供的文件 ID 不可用。”

问题描述

当我尝试使用 google drive api 复制文件时出现错误。有没有我缺少的参数?这是我得到的错误:

{
  "error":{
    "errors":[
      {
        "domain":"global",
        "reason":"fileIdNotUsable",
        "message":"The provided file ID is not usable.",
        "locationType":"other",
        "location":"file.id"
      }
    ],
    "code":400,
    "message":"The provided file ID is not usable."
  }
}

这是我的代码:

    $client = new \Google_Client();
    $client->setClientId(env('GOOGLE_DRIVE_CLIENT_ID'));
    $client->setClientSecret(env('GOOGLE_DRIVE_CLIENT_SECRET'));
    $client->refreshToken(env('GOOGLE_DRIVE_REFRESH_TOKEN'));
    $service = new \Google_Service_Drive($client);

    $optParams = array(
      'pageSize' => 10,
      'fields' => 'nextPageToken, files(id, name)'
    );
    $files = $service->files->listFiles($optParams);
    foreach($files as $value){
      if($value->mimeType != 'application/vnd.google-apps.folder'){
        $service->files->copy($value->id, $value);
      }
    }

标签: phplaravelgoogle-drive-api

解决方案


推荐阅读