php - Google MyBusiness API PHP 位置
问题描述
这是我第一次遇到 Google MyBusiness API。我试图检索帐户位置,但我一无所获。
我没有直接访问帐户的权限,我的客户通过 json 文件让我访问了 API。
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/plus.business.manage');
$service = new Google_Service_MyBusiness($client);
$accounts = $service->accounts->listAccounts();
而且我没有任何错误,只是Google_Service_MyBusiness_ListAccountsResponse
反对,然后放弃foreach
该对象,我可以获得帐户信息:
object(Google_Service_MyBusiness_Account)[94]
protected 'internal_gapi_mappings' =>
array (size=0)
empty
public 'accountName' => null
public 'accountNumber' => null
public 'name' => string 'accounts/XXXXXXXXXXXXXXXXXXXXX' (length=30)
protected 'organizationInfoType' => string 'Google_Service_MyBusiness_OrganizationInfo' (length=42)
protected 'organizationInfoDataType' => string '' (length=0)
public 'permissionLevel' => null
public 'profilePhotoUrl' => string '.../photo.jpg' (length=94)
public 'role' => null
protected 'stateType' => string 'Google_Service_MyBusiness_AccountState' (length=38)
protected 'stateDataType' => string '' (length=0)
public 'type' => string 'PERSONAL' (length=8)
protected 'modelData' =>
array (size=0)
empty
protected 'processed' =>
array (size=0)
empty
public 'state' =>
object(Google_Service_MyBusiness_AccountState)[84]
protected 'internal_gapi_mappings' =>
array (size=0)
empty
public 'status' => string 'UNVERIFIED' (length=10)
protected 'modelData' =>
array (size=0)
empty
protected 'processed' =>
array (size=0)
empty
现在当我尝试:
$name = $account->getName(); //accounts/XXXXXXXXXXXXXXXXXXXXX
$service->accounts_locations->listAccountsLocations($name);
我得到几乎空的Google_Service_MyBusiness_ListLocationsResponse
对象:
object(Google_Service_MyBusiness_ListLocationsResponse)[88]
protected 'collection_key' => string 'locations' (length=9)
protected 'internal_gapi_mappings' =>
array (size=0)
empty
protected 'locationsType' => string 'Google_Service_MyBusiness_Location' (length=34)
protected 'locationsDataType' => string 'array' (length=5)
public 'nextPageToken' => null
public 'totalSize' => null
protected 'modelData' =>
array (size=0)
empty
protected 'processed' =>
array (size=0)
empty
怎么了?我是在做错什么,还是我有错误的凭据(?)。我如何检查/询问客户他给了我正确的访问权限。他可以在他的面板中检查帐户名称吗?
解决方案
您似乎正在尝试使用服务帐户。根据文档基本设置,您需要创建一个 Oauth2 客户端并使用它来登录可以访问我的企业帐户的帐户。
根据文档,Google MyBusiness API 似乎不支持服务帐户。
推荐阅读
- git - 我的工作目录中这个奇怪的文件是什么?
- angular - 更改垫子滑块的颜色
- .net - 功能
在剃刀页面上返回空字符串 - firebase - 我想知道如何在使用 firebase 运行应用程序时保持登录状态
- javascript - FullCalendar 在事件标题中显示 HTML
- php - 使用 dev_appserver.py 托管项目会为部署到 Google Cloud 提供不同的结果
- vagrant - 带有 Hyper-V 的 Vagrantbox 未启动
- css - 以 id 为目标的元素内的某处按 id 定位元素
- node.js - 如何在 cron 作业中设置 UTC 时区
- python - 从列表 Python 中删除后缀