dsft8327 2018-11-02 18:36
浏览 21

获得用户对服务帐户的同意

I'm trying to get info from my business via the Google My Business API but when I try to get the info via their google-api-php-client I'm just getting the following message:

Fatal error:  Uncaught Google_Service_Exception: {
  "error": "unauthorized_client",
  "error_description": "Client is unauthorized to retrieve access tokens using this method."
}

I've followed their documentation (here and here) but with no luck.

Code:

$client = new Google_Client();
$client->setAuthConfig($ga_keyfile);
$client->addScope("https://www.googleapis.com/auth/plus.business.manage");
$client->setClientId($clientID);
$client->setApplicationName($appname);
$client->setAccessType('offline'); // offline access
$client->setSubject("*********@gmail.com");
$client->setIncludeGrantedScopes(true);
$mybusiness = new Google_Service_MyBusiness($client);
echo "<pre>";
print_r($mybusiness->accounts->listAccounts()->getAccounts());
echo "</pre>";

Also I've noticed that this error only occurs when I do $client->setSubject("*********@gmail.com");

If I leave that out it makes requests but then there are no business location available.

I'm not 100% sure if it is because of missing user consent but after googling it looks like it. There is no documentation I've found that explains how to get user consent. Most of them explain what it is but not how to do it.

As 2nd test I've tried creating an auth url with $auth_url = $client->createAuthUrl(); and setting the redirect uri $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php'); (also tried setting it to nothing: '') But then I get a redirect_uri_mismatch error. Which should be correct since you can't set a redirect uri in a service account (or the OAuth2 client of the service account for that matter)

So how can I fix this issue?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 高缺失率数据如何选择填充方式
    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错
    • ¥15 单片机学习顺序问题!!