php - Google API My Business + PHP + Laravel - 找不到类
问题描述
我使用 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_ListAccountsResponse
,Google_Service_MyBusiness_Location
在 中app/Vendors/MyBusiness.php
)
我的代码有什么问题?
解决方案
在函数 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");
推荐阅读
- c# - 如何在插入失败时获取冲突行的主键?
- sql - 如何从 postgres 函数返回两个 SELECT 语句的结果?
- python - 如何找到所有正好有六个 1 和其余 0 的 32 位二进制数
- jquery - Chrome 中的 Ajax 同步请求失败
- google-cloud-firestore - 是否可以查询 DocumentReference[] 数组?
- reactjs - 获取后如何从道具设置初始状态?
- regex - 正则表达式正在寻找匹配但如果只匹配一次则不计数
- angular - 如何使用 observable 动态更新 Angular Material Table
- mysql - 使用 2 个选择优化 SQL 查询
- python - 重置 Tkinter 窗口,恢复小部件