Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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云存储桶-凭据无效_Php_Google Cloud Platform_Google Cloud Storage - Fatal编程技术网

Php 上载到Google云存储桶-凭据无效

Php 上载到Google云存储桶-凭据无效,php,google-cloud-platform,google-cloud-storage,Php,Google Cloud Platform,Google Cloud Storage,我正在尝试将一个文件上传到我的Google Cloud Bucket,但是我不确定如何包含凭据。我有一个包含凭据的.json文件,可以创建一个ServiceBuilder,但我不知道如何使用它来上传文件(我一直在使用它:) 以下内容返回401:无效凭据: <?php require 'vendor/autoload.php'; use Google\Cloud\Storage\StorageClient; use Google\Cloud\Core\ServiceBuild

我正在尝试将一个文件上传到我的Google Cloud Bucket,但是我不确定如何包含凭据。我有一个包含凭据的.json文件,可以创建一个ServiceBuilder,但我不知道如何使用它来上传文件(我一直在使用它:)

以下内容返回401:无效凭据:

<?php

  require 'vendor/autoload.php';

  use Google\Cloud\Storage\StorageClient;
  use Google\Cloud\Core\ServiceBuilder;

  // Authenticate using a keyfile path
  $cloud = new ServiceBuilder([
      'keyFilePath' => 'keyfile.json'
  ]);

  $storage = new StorageClient([
      'projectId' => 'storage-123456'
  ]);

  $bucket = $storage->bucket('storage-123456');

  // Upload a file to the bucket.
  $bucket->upload(
      fopen('data/file.txt', 'r')
  );

  // Using Predefined ACLs to manage object permissions, you may
  // upload a file and give read access to anyone with the URL.
  $bucket->upload(
      fopen('data/file.txt', 'r'),
      [
          'predefinedAcl' => 'publicRead'
      ]
  );

  // Download and store an object from the bucket locally.
  $object = $bucket->object('file_backup.txt');
  $object->downloadToFile('data/file_backup.txt');

?>

啊,我太胖了

不需要服务生成器:

$storage = new StorageClient([
    'keyFilePath' => 'keyfile.json',
    'projectId' => 'storage-123456'
]);