Php 无需登录即可访问Google My Business API(使用服务帐户)
我想访问与我的帐户和他们的评论相关的位置,因为我使用的是google my business API,我可以访问它(它在OAuthPlayed上工作) 现在我想在不登录我的帐户的情况下访问google my business api,因为我正在尝试使它与服务帐户一起工作。但到目前为止运气不好,请建议如何继续。我已在服务帐户中启用了G套件,我还尝试为my business Manager授予访问服务帐户电子邮件(ID)的权限,但它仍处于邀请状态,因为无法实际接受邀请 当我尝试使用我的帐户作为主题发送请求时Php 无需登录即可访问Google My Business API(使用服务帐户),php,google-api,google-api-php-client,google-my-business-api,Php,Google Api,Google Api Php Client,Google My Business Api,我想访问与我的帐户和他们的评论相关的位置,因为我使用的是google my business API,我可以访问它(它在OAuthPlayed上工作) 现在我想在不登录我的帐户的情况下访问google my business api,因为我正在尝试使它与服务帐户一起工作。但到目前为止运气不好,请建议如何继续。我已在服务帐户中启用了G套件,我还尝试为my business Manager授予访问服务帐户电子邮件(ID)的权限,但它仍处于邀请状态,因为无法实际接受邀请 当我尝试使用我的帐户作为主题发
$client = new Google_Client();
$client->addScope('https://www.googleapis.com/auth/plus.business.manage');
$client->setAuthConfig(dirname(__FILE__) . '/Xyz Review API-service account.json');
$client->setSubject('xyz*****abc@gmail.com');
$business_service_class = new Google_Service_Mybusiness($client);
$result_accounts = $business_service_class->accounts->listAccounts();
echo json_encode($result_accounts);
exit;
答复:
{“nextPageToken”:null}
如果我在主题中使用google服务帐户ID作为电子邮件ID,那么我会得到以下响应
$client->setSubject('xyz-review-service@xyz-review-api.iam.gserviceaccount.com');
答复:
误差500
{“error”:“unauthorized_client”,“error_description”:“请求中的unauthorized client或scope.”
如果我这样做是完全错误的,那么请建议如何继续进行。谢谢。我面临使用谷歌API对我的内部服务进行身份验证的问题。 基本上存在两种方法:
$client_email = 'xxxx@developer.gserviceaccount.com';
$private_key = file_get_contents(__DIR__ . '/../Resources/config/xxxx.p12');
$scopes = array('https://www.googleapis.com/auth/calendar');
$credentials = new \Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key
);
$this->client = new \Google_Client();
$this->client->setAssertionCredentials($credentials);
我不确定API是否能与服务帐户一起工作,但是,据我所知,要以您想要的方式使用服务帐户,您需要启用域范围的委派。我看到Google My Business作为一项服务出现在G套件帐户的“其他Google服务”中。您是否尝试过按照此处的步骤操作?也许您只需要启用DWD。让我知道它是否有效。@Morfinismo我确实在服务帐户中启用了DWD,然后才尝试了上面的api调用。@hmm你有没有让我的业务api与服务帐户一起工作过?如果是,怎么办?@Zath。。。不,伙计。。。试了好几次,但都不管用。也许现在可以用了,但不确定当前版本。我试图找到与Gmail账户相关的地方的平均评级和所有评论。请尝试告诉我您是否解决了这个问题。Google_Auth_AssertionCredentials已从Google api-php版本2中删除。(你可以在这里查看-)我下载了json而不是.p12,而且步骤还是一样,仍然有点不起作用。