Google MyBusiness API PHP位置

时间:2019-05-16 12:44:23

标签: php google-api google-api-php-client service-accounts google-my-business-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

怎么了?我是在做错什么,还是我的凭证有错(?)。我如何检查/询问客户他给了我正确的访问权限。他可以在面板中检查帐户名吗?

1 个答案:

答案 0 :(得分:2)

您似乎正在尝试使用服务帐户。根据文档Basic setup,您需要创建一个Oauth2客户端,并使用该客户端登录有权访问我的企业帐户的帐户。

根据文档,Google MyBusiness API似乎不支持服务帐户。