Repository navigation
listAccountsLocation() "code": 400, "message": "Request contains an invalid argument." Business Information API #2213
Description
Hello guys!
I'm an error with business information API...
im trying to get all locations ID of my account in google my business...
but, when i run the code of "accounts_locations->listAccountsLocations($nameOfAccount)" its return an error..
Infos:
im using PHP library.
Business Information API
Code:
include_once 'vendor/autoload.php';
include_once "google-api-php-client-main/examples/templates/base.php";
echo pageHeader("Retrieving An Id Token");
if (!$oauth_credentials = getOAuthCredentialsFile()) {
echo missingOAuth2CredentialsWarning();
return;
}
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client = new Google\Client();
$client->setAuthConfig($oauth_credentials);
$client->setScopes('email');
$client->addScope("https://www.googleapis.com/auth/business.manage");
$client->setRedirectUri($redirect_uri);
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
die('Logged out.');
}
if (isset($_GET['code'])) { // get auth code, get the token and store it in session
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) { // get token and configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
die;
}
$mybusinessService = new Google_Service_MyBusinessAccountManagement($client);
// Get the first account in the accounts array
$accounts = $mybusinessService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
$account = $accountsList[0];
$name = $accounts->get($account->name)->getName();
var_export($name);
$my_business_account = new Google_Service_MyBusinessBusinessInformation($client);
// Get the first location in the locations array
$locations = $my_business_account->accounts_locations;
$locationsList = $locations->listAccountsLocations($name);
$location = $locationsList[0];
var_export($location);
Return of code:
Fatal error: Uncaught Google\Service\Exception: { "error": { "code": 400, "message": "Request contains an invalid argument.", "errors": [ { "message": "Request contains an invalid argument.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "field": "read_mask", "description": "Field is required" } ] } ] } } in C:\xampp\htdocs\BuzzUp\vendor\google\apiclient\src\Http\REST.php:128 Stack trace: #0 C:\xampp\htdocs\BuzzUp\vendor\google\apiclient\src\Http\REST.php(103): Google\Http\REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google\Service\...') #1 [internal function]: Google\Http\REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google\Service\...') #2 C:\xampp\htdocs\BuzzUp\vendor\g in C:\xampp\htdocs\BuzzUp\vendor\google\apiclient\src\Http\REST.php on line 128
OBS: THE NAME OF ACCOUNT ITS CORRECT... its like this: 'accounts/XXXXX326619521XXXXXXX'
i want to know about locations ID of my account manages.. can someone help me?
Activity
dpi commentedon Feb 17, 2022
This may be due to the new readMask argument. See https://developers.google.com/my-business/content/businessinformation/change-log
luanhduarte commentedon Feb 17, 2022
It's correct!!!
I increase this at my code:
$optParams = array(
'readMask' => 'name',
);
$list_accounts_response = $my_business_account->accounts_locations->listAccountsLocations("accounts/114893266195214446586", $optParams);
var_dump($list_accounts_response);
Thank you..
UVLabs commentedon Apr 6, 2022
If anyone else is coming across this. You need to create a read mask like the comment above but if you want multiple fields you'd write it like this:
The possible fields can be seen on this page: https://developers.google.com/my-business/reference/businessinformation/rest/v1/locations
dhirendralab commentedon Jun 13, 2022
I am getting below error message
(list) unknown parameter: 'readMask'
bshaffer commentedon Jun 13, 2022
@dhirendralab I'm not sure which method you're using, but for listing accounts locations, you can see
readMaskis a parameter. I think you must be calling a differentlistmethod which does not respect the "readMask" parameter.