Skip to content

listAccountsLocation() "code": 400, "message": "Request contains an invalid argument." Business Information API #2213

Closed

Description

@luanhduarte

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

  1. dpi commented on Feb 17, 2022

    @dpi
  2. luanhduarte commented on Feb 17, 2022

    @luanhduarte
    Author

    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..

  3. UVLabs commented on Apr 6, 2022

    @UVLabs

    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:

    $optParams = array(
           'readMask' => array(
               'name',
               'title',
               'profile',
           ),
    );
    

    The possible fields can be seen on this page: https://developers.google.com/my-business/reference/businessinformation/rest/v1/locations

  4. dhirendralab commented on Jun 13, 2022

    @dhirendralab

    I am getting below error message

    (list) unknown parameter: 'readMask'

  5. bshaffer commented on Jun 13, 2022

    @bshaffer
    Contributor

    @dhirendralab I'm not sure which method you're using, but for listing accounts locations, you can see readMask is a parameter. I think you must be calling a different list method which does not respect the "readMask" parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions