Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无需登录即可访问Google My Business API(使用服务帐户)_Php_Google Api_Google Api Php Client_Google My Business Api - Fatal编程技术网

Php 无需登录即可访问Google My Business API(使用服务帐户)

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)的权限,但它仍处于邀请状态,因为无法实际接受邀请 当我尝试使用我的帐户作为主题发

我想访问与我的帐户和他们的评论相关的位置,因为我使用的是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对我的内部服务进行身份验证的问题。 基本上存在两种方法:

  • 创建页面以接受您的应用程序以访问google帐户
  • 创建证书以通过“隐式”批准对应用程序进行身份验证
  • 正如我所说,我正在使用GoogleAPI进行一个内部项目,因此第一个选项是毫无疑问的(该服务不是公开的)。 转到并创建新项目,然后转到“api管理器”,然后转到“凭据”,然后创建“服务凭据”

    如果您执行了所有这些步骤,您就拥有一个扩展名为.p12的证书,它是您访问google api的密钥(请记住,您必须启用该密钥才能访问所需的特定google 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,而且步骤还是一样,仍然有点不起作用。