php-google-my-business icon indicating copy to clipboard operation
php-google-my-business copied to clipboard

v4 APIs are deprecated

Open mzohaibnaz opened this issue 2 years ago • 9 comments

hey i'm wondering when we will have new version for this package which will support new google my business apis.

mzohaibnaz avatar Apr 21 '22 17:04 mzohaibnaz

waiting for it :)

Coding-007 avatar Apr 22 '22 17:04 Coding-007

this package will no longer work after 30 April, I'm just wondering how long should I wait :)

mzohaibnaz avatar Apr 25 '22 16:04 mzohaibnaz

I have updated my all APIs with new GMB PHP API Clients v1. As well there are some endpoints that are still using v4.9, so for them, I am still using this class.

Coding-007 avatar Apr 26 '22 07:04 Coding-007

@Coding-007

Currently in the process of being replaced. I could not call listLocationsQuestions with a new endpoint. I am having trouble with the read_mask in the error response because the argument does not exist.

If you know how to solve this problem, please let me know :)

  • composer require "google/apiclient": "2.12.4",
/**
 * Service definition for MyBusinessQA (v1).
 *
 * <p>
 * The My Business Q API allows questions and answers to be posted for specific
 * listings.</p>
 *
 * <p>
 * For more information about this service, see the API
 * <a href="https://developers.google.com/my-business/" target="_blank">Documentation</a>
 * </p>
 *
 * @author Google, Inc.
 */
class MyBusinessQA extends \Google\Service {}
  • sample request
private function _getClient() {
    $config = static::getConfig();

    $client = new \Google\Client();
    $client->setClientId($config['clientId']);
    $client->setClientSecret($config['clientSecret']);
    $client->setRedirectUri($config['redirectUri']);
    $client->addScope($config['scopes']);
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    $client->setState(uuid());
    $client->setApiFormatV2(true);
    $client->setApplicationName('xxx');

    return $client;
}

// My Business Q&A API
// https://console.cloud.google.com/apis/api/mybusinessqanda.googleapis.com/metrics?project=xxx
// https://developers.google.com/my-business/content/qanda/change-log
$service = new MyBusinessQA($this->_getClient());
$locationName = 'xxx/xxx';
return $service->locations_questions->listLocationsQuestions($locationName)->getQuestions();
  • response
2022-05-10 13:54:46 Error: {
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "read_mask",
            "description": "Field is required"
          }
        ]
      }
    ]
  }
}

basi avatar May 10 '22 05:05 basi

Read_mask field needs to be sent while fetching resources. Field read_mask is a list of properties against a specific API you want to get. Suppose a listing has a name, title, and address and I have to get the name and title, so I have to send read_mask in which I will mention my desired properties. Here is a code section from my code.

// import your required class like this, like questions, etc
use Google\Service\MyBusinessBusinessInformation;

$account_name = $account['name'];
$optional_params = [];
$optional_params['pageSize'] = 100;
$optional_params['readMask'] = ['name', 'title', 'storefrontAddress', 'latlng', 'phoneNumbers', 'Metadata'];

$this->gmb_info_service = new MyBusinessBusinessInformation($this->client);
$locations = $this->gmb_info_service->accounts_locations->listAccountsLocations($account_name,$optional_params);

Coding-007 avatar May 10 '22 05:05 Coding-007

thanks!

MyBusinessBusinessInformation can be called in the same way. Cannot call My Business Q&A API. Is it possible to retrieve questions and answers?

Also, where can I find a list of readMasks required for each api?

// My Business Q&A API
// https://console.cloud.google.com/apis/api/mybusinessqanda.googleapis.com/metrics?project=xxx
// https://developers.google.com/my-business/content/qanda/change-log

use Google\Service\MyBusinessQA;

$service = new MyBusinessQA($this->_getClient());
$locationName = 'xxx/xxx';
return $service->locations_questions->listLocationsQuestions($locationName)->getQuestions();

basi avatar May 10 '22 12:05 basi

Here are a few links, so you can get the idea of read mask.

  1. https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask
  2. https://developers.google.com/my-business/reference/businessinformation/rpc/google.mybusiness.businessinformation.v1?hl=en

Coding-007 avatar May 11 '22 03:05 Coding-007

thanks!

The conclusion was a bug in google-api-php-client-services. https://github.com/googleapis/google-api-php-client-services/pull/1010/files https://github.com/googleapis/google-api-php-client-services/issues/956

basi avatar May 11 '22 09:05 basi

Notice that not all MyBusiness APIs have counterparts in the new MyBusinessInformation API, e.g. location reviews. For these this package is still necessary and works.

mbrodala avatar May 25 '22 08:05 mbrodala