微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Google My Business API 中获取位置列表 | PHP

如何解决如何在 Google My Business API 中获取位置列表 | PHP

如何在 Google My Business API 中获取位置列表。我在哪里检索了帐户列表,但我不知道如何检索位置。

这是我获取帐户列表的代码

define('GOOGLE_CLIENT_ID','XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define('GOOGLE_CLIENT_SECRET','XXXXXXXXXXXXX');

// Create Client Request to access Google Api
$client = new Client();
$client->setApplicationName('my-app');
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri('https://example.com/callback');
$client->addScope('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/business.manage');
$client->setAccesstype('offline');        // offline access
$client->setIncludeGrantedScopes(true);   // incremental auth

$client->setAccesstoken($accesstoken);

$service = new \Google_Service_MyBusinessAccountManagement($client);
$accounts = $service->accounts->listAccounts()->getAccounts(); // get accounts

解决方法

要获取谷歌位置,
您可以使用这个 PHP My Business file 让事情变得更简单。

首先将范围更改为 ttps://www.googleapis.com/auth/plus.business.manage,然后包含文件并与您的客户一起创建 Google_Service_MyBusiness 的对象,然后执行此操作。

 $mybusinessService = new Google_Service_MyBusiness($client);
 // Get the first account in the accounts array
    $accounts = $mybusinessService->accounts;
    $accountsList = $accounts->listAccounts()->getAccounts();
    $account = $accountsList[0];


    // Get the first location in the locations array
    $locations = $mybusinessService->accounts_locations;
    $locationsList = $locations->listAccountsLocations($account->name)->getLocations();
    $location = $locationsList[0];
    var_export($location);

通过此过程,您还可以获得谷歌评论。

有关详细信息,请查看此 Google Business API documentation

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。