首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从Google检索我的商业评论

如何从Google检索我的商业评论
EN

Stack Overflow用户
提问于 2019-11-09 05:09:55
回答 1查看 386关注 0票数 2

我可以连接到Google My Business并打电话返回账号,但我无法列出与该帐户关联的位置,也无法检索评论。

代码语言:javascript
运行
复制
require_once( '/functions/google-api-php-client/vendor/autoload.php' );
require_once( '/functions/mybusiness/MyBusiness.php' );

$client = new Google_Client();

if ( $credentials_file = checkServiceAccountCredentialsFile() ) {
    // set the location manually
    $client->setAuthConfig( $credentials_file );
} elseif ( getenv( 'GOOGLE_APPLICATION_CREDENTIALS' ) ) {
    // use the application default credentials
    $client->useApplicationDefaultCredentials();
} else {
    echo missingServiceAccountDetailsWarning();

    return;
}

$client->setApplicationName( "Cardall_Orthodontics_Reviews" );
$client->setScopes( [ 'https://www.googleapis.com/auth/plus.business.manage' ] );
$service = new Google_Service_Mybusiness( $client );

$accounts     = $service->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
$account      = $accountsList[0];

$locations     = $service->accounts_locations;
$locationsList = $locations->listAccountsLocations( $account->name )->getLocations(); // This is where it's not returning the locations
$location      = $locationsList[0];

$reviews             = $service->accounts_locations_reviews;
$listReviewsResponse = $reviews->listAccountsLocationsReviews( $location->name );
$reviewsList         = $listReviewsResponse->getReviews();

当我打印$ account ->name时,我可以看到accounts/000000000000000000000 (带有我的帐户ID),所以我只是假设它在那之前是有效的,但是我不确定为什么没有任何位置。我已经在我的业务帐户中添加了一个。

EN

回答 1

Stack Overflow用户

发布于 2021-11-12 10:50:18

您必须在查询中添加所需的参数"readMask":

代码语言:javascript
运行
复制
$locationsList = $locations
    ->listAccountsLocations(
        $account->name,
        ['readMask' => ['name', 'title',]]
    )
    ->getLocations();

https://developers.google.com/my-business/reference/businessinformation/rest/v1/accounts.locations/list

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58773832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档