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

时间:2019-11-08 21:09:54

标签: php google-my-business-api

我可以连接到“ 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();

当我打印$ account-> name时,我可以看到accounts/000000000000000000000(带有我的帐户ID),因此我只是假设它在此之前一直在工作,但是我不确定为什么不这样做在任何位置。我的商家帐户中添加了一个。

0 个答案:

没有答案