Php 致命错误:类';谷歌(Google)断言定义';

Php 致命错误:类';谷歌(Google)断言定义';,php,oauth,google-drive-api,Php,Oauth,Google Drive Api,目前,我不得不放弃在OneDrive中创建文件夹的权利。我改用了谷歌硬盘,现在我有了更多的成功 所以我试图在Google Drive中创建一个文件夹,但是我收到了主题错误消息 <?php require_once 'vendor/autoload.php'; require_once 'vendor/google/apiclient/src/Google/Client.php'; require_once 'vendor/google/apiclient-services/sr

目前,我不得不放弃在OneDrive中创建文件夹的权利。我改用了谷歌硬盘,现在我有了更多的成功

所以我试图在Google Drive中创建一个文件夹,但是我收到了主题错误消息

<?php
  require_once 'vendor/autoload.php';
  require_once 'vendor/google/apiclient/src/Google/Client.php';
  require_once 'vendor/google/apiclient-services/src/Google/Service/Drive.php';

  $client = new Google_Client();
  $client->setClientId('myclientID');
  $client->setClientSecret('myclientSecret');
  $client->setRedirectUri('myredirectURI');
  $client->setScopes(array('https://www.googleapis.com/auth/drive.file'));

  session_start();

  function buildService() {//function for first build up service
    global $DRIVE_SCOPE, $SERVICE_ACCOUNT_EMAIL, $SERVICE_ACCOUNT_PKCS12_FILE_PATH;
    $key = file_get_contents($SERVICE_ACCOUNT_PKCS12_FILE_PATH);
    $auth = new Google_AssertionCredentials($SERVICE_ACCOUNT_EMAIL,array($DRIVE_SCOPE),$key);
    $client = new Google_Client();
    $client->setUseObjects(true);
    $client->setAssertionCredentials($auth);
    return new Google_DriveService($client);
  }

  function createPublicFolder($service, $folderName) {
    $file = new Google_DriveFile();
    $file->setTitle($folderName);
    $file->setMimeType('application/vnd.google-apps.folder');

    $createdFile = $service->files->insert($file, array(
      'mimeType' => 'application/vnd.google-apps.folder',
    ));

    $permission = new Google_Permission();
    $permission->setValue('me');
    $permission->setType('anyone');
    $permission->setRole('writer');

    $service->permissions->insert(
      $createdFile->getId(), $permission);
      return $createdFile;
  }


  $DRIVE_SCOPE = 'https://www.googleapis.com/auth/drive';
  $SERVICE_ACCOUNT_EMAIL = 'my.email@mine.com';
  $SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'main docs dummy-x456d55d8371.p12';

  $service=buildService();
  $folderName='root_test';
  $parent=createPublicFolder($service, $folderName);
?>

这个错误让我相信OAuth有问题,但我不确定我到底缺少了什么。我认为autoload.php可以处理这个问题。

这取决于您使用的版本:

  • 对于1.0,您可能正在寻找
    Google\u Auth\u断言属性
  • 对于2.0,这是一门课
Fatal error: Class 'Google_AssertionCredentials' not found