Google 我的业务 API PHP 地点
Google MyBusiness API PHP Locations
这是我第一次 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
怎么了?我做错了什么,或者我有错误的凭据(?)。我怎么才能check/ask客户端说他给了我正确的访问权限。他可以在他的面板中检查帐户名称吗?
您似乎正在尝试使用服务帐户。根据文档 Basic setup,您需要创建一个 Oauth2 客户端并使用它来登录有权访问我的企业帐户的帐户。
根据文档,Google MyBusiness API 似乎不支持服务帐户。
这是我第一次 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
怎么了?我做错了什么,或者我有错误的凭据(?)。我怎么才能check/ask客户端说他给了我正确的访问权限。他可以在他的面板中检查帐户名称吗?
您似乎正在尝试使用服务帐户。根据文档 Basic setup,您需要创建一个 Oauth2 客户端并使用它来登录有权访问我的企业帐户的帐户。
根据文档,Google MyBusiness API 似乎不支持服务帐户。