Google Drive Service: "Catchable fatal error: Argument 1 passed to Google_DriveService::__construct() must be an instance of Google_Client"

Google Drive Service: "Catchable fatal error: Argument 1 passed to Google_DriveService::__construct() must be an instance of Google_Client"

所以是的,这个错误只是让它看起来像参数不是 Google Drive Service 的实例。我上下寻找有类似错误的人,但我一无所获。这是完整的错误,然后是我的代码:

可捕获的致命错误:传递给 Google_DriveService::__construct() 的参数 1 必须是给定的 Google_Client、none 的实例,在 php-google-oauth/data2.[=29= 中调用] 在第 23 行,并在第 1041 行 php-google-oauth/src/contrib/Google_DriveService.php 中定义

Google_DriveService.php(1041行左右):

class Google_DriveService extends Google_Service {
  public $about;
  public $apps;
  public $changes;
  public $children;
  public $comments;
  public $files;
  public $parents;
  public $permissions;
  public $replies;
  public $revisions;
  /**
    * Constructs the internal representation of the Drive service.
    *
    * @param Google_Client $client
  */
  public function __construct(Google_Client $client) { //LINE 1021
  $this->servicePath = 'drive/v2/';
  $this->version = 'v2';
  $this->serviceName = 'drive';
  // ....

data2.php:

// ..... (defining GDRIVE_...s)
$client = new Google_Client();
$client->setClientId( GDRIVE_CLIENT_ID );
$client->setClientSecret( GDRIVE_CLIENT_SECRET );
$client->setRedirectUri( GDRIVE_REDIRECT_URIS );
$client->setScopes( array( GDRIVE_SCOPE_01, GDRIVE_SCOPE_02, GDRIVE_SCOPE_03, GDRIVE_SCOPE_04, GDRIVE_SCOPE_05 ) );
$service = new Google_DriveService(); // LINE 23
// ....

我在调用云端硬盘服务之前调用了 Google_Client() class 实例...所以我不确定发生了什么。

Argument 1 passed to Google_DriveService::__construct() must be an instance of Google_Client, none given

这意味着你必须在实例化时传递(至少)一个参数 Google_DriveService 并且你传递的参数必须是 Google_Client class.[=15 的实例=]

而不是这个:

$service = new Google_DriveService();

你需要:

$service = new Google_DriveService($client);