简体   繁体   English

如何从 Google 检索“我的商家”评论

[英]How to retrieve My Business reviews from Google

I'm able to connect to Google My Business and make a call to return the account number, but I can't list the locations associated to the account, and in turn, can't retrieve the reviews.我可以连接到“Google 我的商家”并拨打电话以返回帐号,但我无法列出与该帐户关联的位置,进而无法检索评论。

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();

When I print $account->name, I can see accounts/000000000000000000000 (with my account ID) so I'm only assuming it's working up until that point, but I'm not sure why there wouldn't be any locations.当我打印 $account->name 时,我可以看到accounts/000000000000000000000 (带有我的帐户 ID)所以我只是假设它一直工作到那时,但我不确定为什么不会有任何位置。 I have one added in My Business account.我在我的企业帐户中添加了一个。

You must add to your query required param "readMask":您必须在查询中添加所需的参数“readMask”:

$locationsList = $locations
    ->listAccountsLocations(
        $account->name,
        ['readMask' => ['name', 'title',]]
    )
    ->getLocations();

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM