0

我使用 OAuth 2.0 流 + google-api-php-client + Mybusiness PHP 类,但出现“找不到类”错误,见下文:

use App\Vendors\Google_Service_MyBusiness as MyBusiness;
....

$gClient->setAccessToken($access_token);
$oauth2 = new \Google_Service_Oauth2($gClient);
$userInfo = $oauth2->userinfo->get();
print_r($userInfo); //Works!

$mybusinessService = new MyBusiness($gClient);

//return Class 'Google_Service_MyBusiness_Location' not found:
$mybusinessService->accounts->get('accounts/xxxxxxxx');

//return 'Google_Service_MyBusiness_ListAccountsResponse' not found:
$accounts = $mybusinessService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();

完整错误:

Class 'Google_Service_MyBusiness_Account' not found in file /vendor/google/apiclient/src/Google/Http/REST.php on line 128

自动加载中添加的 MyBusiness 类:

"autoload" : {
    "files": [
        "app/Vendors/MyBusiness.php"
    ]
}

所有必需的类(例如Google_Service_MyBusiness_ListAccountsResponseGoogle_Service_MyBusiness_Location在 中app/Vendors/MyBusiness.php

我的代码有什么问题?

4

2 回答 2

1

在函数 listAccounts() 处更改,第 1262 行

从:

return $this->call('list', array($params), "Google_Service_MyBusiness_ListAccountsResponse");

至:

return $this->call('list', array($params), "App\Services\Integrations\GoogleApi\Google_Service_MyBusiness_ListAccountsResponse");
于 2019-12-23T19:49:39.307 回答
0

供应商目录不在App/Vendor.

像这样试试

$service = new \Google_Service_MyBusiness($client);
于 2019-12-30T04:58:59.817 回答