如何在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文件来简化操作。

首先将作用域更改为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文档。

希望它能帮助

"这是正确的!!!

我在我的代码上增加了这个:

$optParams = array(
'readMask' => 'name',
);
$list_accounts_response = $my_business_account->accounts_locations->listAccountsLocations("accounts/114893266195214446586", $optParams);
var_dump($list_accounts_response);

谢谢">

来源:https://github.com/googleapis/google-api-php-client/issues/2213#issuecomment-1042785983

最新更新