【问题标题】: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 的实例”
【发布时间】:2015-04-27 05:20:22
【问题描述】:

所以是的,这个错误只是让参数看起来不是 Google 云端硬盘服务的实例。我一直在寻找有类似错误的人,但我一无所获。这是完整的错误,然后是我的代码:

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

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
// ....

我在调用 Drive 服务之前调用了 Google_Client() 类实例...所以我不确定发生了什么。

【问题讨论】:

    标签: php google-api-php-client google-client


    【解决方案1】:

    传递给 Google_DriveService::__construct() 的参数 1 必须是 Google_Client 的实例,没有给出

    这意味着您在实例化Google_DriveService 时必须(至少)传递一个参数,并且您传递的参数必须是Google_Client 类的实例。

    而不是这个:

    $service = new Google_DriveService();
    

    你需要:

    $service = new Google_DriveService($client);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-29
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多