php-google-my-business
php-google-my-business copied to clipboard
v4 APIs are deprecated
hey i'm wondering when we will have new version for this package which will support new google my business apis.
waiting for it :)
this package will no longer work after 30 April, I'm just wondering how long should I wait :)
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
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"
}
]
}
]
}
}
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);
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();
Here are a few links, so you can get the idea of read mask.
- https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask
- https://developers.google.com/my-business/reference/businessinformation/rpc/google.mybusiness.businessinformation.v1?hl=en
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
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.