Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Google Drive V3,Google API客户端2.0-批量上载失败_Php_Google Api_Google Drive Api_Google Api Php Client - Fatal编程技术网

Php Google Drive V3,Google API客户端2.0-批量上载失败

Php Google Drive V3,Google API客户端2.0-批量上载失败,php,google-api,google-drive-api,google-api-php-client,Php,Google Api,Google Drive Api,Google Api Php Client,使用带有API(v2.0)主分支的Google Drive V3批量上载失败 我已使用服务帐户凭据进行了修改 守则: include_once __DIR__ . '/../vendor/autoload.php'; include_once "templates/base.php"; echo pageHeader("Batching Queries"); // USE TRUE OR FALSE TO TOGGLE BETWEEN BATCHED AND SEQUENTIAL UPLOA

使用带有API(v2.0)主分支的Google Drive V3批量上载失败

我已使用服务帐户凭据进行了修改

守则:

include_once __DIR__ . '/../vendor/autoload.php';
include_once "templates/base.php";

echo pageHeader("Batching Queries");

// USE TRUE OR FALSE TO TOGGLE BETWEEN BATCHED AND SEQUENTIAL UPLOADS.
$useBatch = true;

$client = new Google_Client();
$client->setScopes([
    'https://www.googleapis.com/auth/drive',
]);
if ($credentials_file = checkServiceAccountCredentialsFile()) {
  // set the location manually
  $client->setAuthConfig($credentials_file);
} elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
  // use the application default credentials
  $client->useApplicationDefaultCredentials();
} else {
  exit;
}
$client->setSubject('some@email.com');
$service = new Google_Service_Drive($client);
$client->setUseBatch($useBatch);

if ($useBatch) {
    $batch = $service->createBatch();
}

$folder = new Google_Service_Drive_DriveFile([
  'name' => 'Invoices',
  'mimeType' => 'application/vnd.google-apps.folder'
]);

$req = $service->files->create($folder, [
  'fields' => 'id'
]);

if ($useBatch) {
    $result = $batch->add($req, 'newfolder');
    $folder = $batch->execute()['response-newfolder'];
    $newFolderId = $folder->id;
} else {
    $newFolderId = $req->id;
}

$uploadIDs = null;

if ($useBatch) {
    $batch = $service->createBatch();
}

for ($i=1;$i<=3;$i++) {
    $file = new Google_Service_Drive_DriveFile([
        'name' => $i . '.jpg',
        'mimeType' => 'image/jpeg',
        'parents' => [$newFolderId],
    ]);

    $req = $service->files->create($file, [
        'data' => file_get_contents('img/'.$i.'.jpg'),
        'mimeType' => 'image/jpeg',
        'uploadType' => 'media',
        'fields' => 'id',
    ]);

    if ($useBatch) {
        $batch->add($req, $i);
    } else {
        $uploadIDs[] = $req->id;
    }
}

if ($useBatch) {
    $results = $batch->execute();
} else {
    print_r($uploadIDs);
}
include_once uuuu DIR_uuuu.//供应商/autoload.php';
包括_once“templates/base.php”;
echo页面标题(“批处理查询”);
//使用TRUE或FALSE在批处理和顺序上载之间切换。
$useBatch=true;
$client=新的Google_客户端();
$client->setscope([
'https://www.googleapis.com/auth/drive',
]);
如果($credentials\u file=checkServiceAccountCredentialsFile()){
//手动设置位置
$client->setAuthConfig($credentials\u文件);
}elseif(getenv('GOOGLE\u应用程序\u凭据')){
//使用应用程序默认凭据
$client->useApplicationDefaultCredentials();
}否则{
出口
}
$client->setSubject($client)some@email.com');
$service=新的谷歌服务驱动器($client);
$client->setUseBatch($useBatch);
如果($useBatch){
$batch=$service->createBatch();
}
$folder=新Google\u服务\u驱动器\u驱动器文件([
“名称”=>“发票”,
'mimeType'=>'应用程序/vnd.google apps.folder'
]);
$req=$service->files->create($folder)[
“字段”=>“id”
]);
如果($useBatch){
$result=$batch->add($req,'newfolder');
$folder=$batch->execute()['response-newfolder'];
$newFolderId=$folder->id;
}否则{
$newFolderId=$req->id;
}
$uploadIDs=null;
如果($useBatch){
$batch=$service->createBatch();
}
对于($i=1;$i$i.'.jpg',
'mimeType'=>'image/jpeg',
“家长”=>[$newFolderId],
]);
$req=$service->files->create($file)[
'data'=>文件获取内容('img/'.$i..jpg'),
'mimeType'=>'image/jpeg',
'uploadType'=>'media',
“字段”=>“id”,
]);
如果($useBatch){
$batch->add($req,$i);
}否则{
$uploadIDs[]=$req->id;
}
}
如果($useBatch){
$results=$batch->execute();
}否则{
打印(上传ID);
}
在运行最后一个$results=$batch->execute()之后,上述代码将以“notfound”失败;(将成功创建文件夹发票)

使用
$useBatch=false
一切正常-创建一个包含三个文件的文件夹

为什么批量上传会崩溃

谢谢

根据,您收到“404未找到文件”,原因是用户没有文件的读取权限或文件不存在。建议的操作:向用户报告他们没有该文件的读取权限或该文件不存在。告诉他们,他们应该向文件所有者请求对该文件的许可

您必须将您的“$fileId”包含在您的文件中。此外,如果“$useBatch=true”,则应设置“$userPermission”

注意:您应该使用此处所述的:

根据,您收到“404文件未找到”,原因是用户没有文件的读取权限或文件不存在。建议的操作:向用户报告他们没有该文件的读取权限或该文件不存在。告诉他们,他们应该向文件所有者请求对该文件的许可

您必须将您的“$fileId”包含在您的文件中。此外,如果“$useBatch=true”,则应设置“$userPermission”

注意:您应使用如下所述的:

目前,Google Drive不支持媒体的批处理操作, 可供上传或下载

资料来源:

目前,Google Drive不支持媒体的批处理操作, 可供上传或下载


来源:

我没有任何“$fileId”。我正在上传文件,而不是修改它们。所以“404文件未找到”看起来完全是随机的,不合适。我没有任何“$fileId”。我正在上传文件,而不是修改它们。所以“404文件未找到”看起来完全是随机的,不合适。向谷歌提交了一份错误报告:向谷歌提交了一份错误报告: