PHP - Google MyBusiness список отзывов API-вызов не работает - PullRequest
0 голосов
/ 09 ноября 2019

Я просто хочу получить отзывы клиентов Google о своем бизнесе, чтобы они отображались на их веб-сайте.

Вот код. Я не знаю, нужно ли мне использовать служебную учетную запись (которую я настроил на всякий случай) или просто OAUTH2.0.

Я также не знаю, как получить токен доступа.

    $client = new Google_Client();
    $devkey = '';
    $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

    $client->setDeveloperKey($devkey);
    $client->setRedirectUri($redirect_uri);
    $client->setAccessType('offline');
    $client->setApprovalPrompt('none');
    $client->setIncludeGrantedScopes(true);
    $client->setApplicationName('es-testimonials');
    $client->addScope('https://www.googleapis.com/auth/business.manage');

/* THIS IS THE SERVICE ACCOUNT CODE I'VE PLAYED WITH

    putenv('GOOGLE_APPLICATION_CREDENTIALS=../google-api-php-client-2.4.0/###.json');
    $client->useApplicationDefaultCredentials();
    $user_to_impersonate = '';
    $client->setSubject($user_to_impersonate);
*/
    $hush = '../google-api-php-client-2.4.0/###.json';
    try {
        $client->setAuthConfig($hush);
    } catch (Google_Exception $e) {
        $pc.=$e;
    }

$reviews = new Google_Service_MyBusiness($client);

$location = 'accounts/###/locations/###';
$optParams = ['pageSize' => '20', 'orderBy' => 'rating desc'];


    try {
        $response = $reviews->accounts_locations_reviews;
        $list = $response->listAccountsLocationsReviews($location);
    }catch(Google_Service_Exception $e){
            $pc.=$e;
    }

В зависимости от того, какой код я комментирую, я получаю:

{
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "errors": [ {
      "message": "Requested entity was not found.",
      "domain": "global",
      "reason": "notFound"
    } ],
    "status": "NOT_FOUND"
  }
}

или

{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "errors": [ {
      "message": "Login Required.",
      "domain": "global",
      "reason": "required",
      "location": "Authorization",
      "locationType": "header"
    } ],
    "status": "UNAUTHENTICATED"
  }
}

С того момента, когда я пытаюсь позвонить на конечную точку listaccountlocationreviews.

Может кто-нибудь дать мне какой-нибудь совет?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...