我通过使用 google api 客户端从 accouts list 功能中获得 404。
我已经使用 OAuth2.0 访问令牌。除此之外,我已经通过 https://console.developers.google.com 为 OAuth 2.0 启用了 Google My Business API。
■这里是环境
PHP 7.2.3
Ubuntu 18.04 LTS
谷歌/apiclient ^2.5
我要执行的功能如下。 https://developers.google.com/my-business/reference/rest/v4/accounts/list
我使用以下链接中的作曲家安装谷歌客户端库。 https://github.com/googleapis/google-api-php-client
由于谷歌我的商业图书馆是分开的,我使用这个程序。 https://developers.google.com/my-business/samples
产生404的步骤是......
$client = new Google_Client();
$client->setApplicationName("post_dev"); // app name
$client->setApprovalPrompt('force');
$client->setAccessType('offline');
$client->setAccessToken($credential);
$client->addScope("https://www.googleapis.com/auth/business.manage");
$client->addScope("https://www.googleapis.com/auth/plus.business.manage");
$gmbService = new Google_Service_MyBusiness($client);
$results = $gmbService->accounts->listAccounts();
变量 $credential 具有以下值。
client_id
client_secret
access_token
expires_in
refresh_token
执行程序后,我得到 404 错误,如下所示。
Google_Service_Exception[
404
]: {
"error": {
"code": 404,
"message": "Method not found.",
"errors": [
{
"message": "Method not found.",
"domain": "global",
"reason": "notFound"
}
],
"status": "NOT_FOUND"
}
}
到目前为止,我可以在此处使用PHP库 - https://developers.google.com/my-business/samples/previousVersions
但是上面的答案是一个巨大的帮助 - 我遇到了完全相同的问题,已经“整理”了我的项目 - 在被授予Google访问Google My Business API并看到我的其他项目之后,我认为我的其他项目会不正确地使用它能够使用它 - 错误!很高兴我在这里找到了答案。幸运的是,我能够恢复要删除的项目,并使用它立即使用的项目。