Skip to content

Instantly share code, notes, and snippets.

@SudoPlz
Created October 26, 2023 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SudoPlz/56f58cdd77355935e3de461ee92c2ddb to your computer and use it in GitHub Desktop.
Save SudoPlz/56f58cdd77355935e3de461ee92c2ddb to your computer and use it in GitHub Desktop.
/**
* @param string $parentAccountName - the account id you want to fetch locations for (i.e. accounts/105837778216009211413)
* @param array|string|null $readMask - the fields you want to include in the response, available fields here https://developers.google.com/my-business/reference/businessinformation/rest/v1/locations#resource:-location
* @return array
* @throws Exception
*/
public function getAllLocationsForAccount(string $parentAccountName, array|string|null $readMask = "name,title,storecode,labels"): array
{
$businessInformationService = new MyBusinessBusinessInformation($this->client);
try {
$locations = $businessInformationService->accounts_locations->listAccountsLocations($parentAccountName, [
"readMask" => $readMask
]);
} catch (Google_Service_Exception $exception) { // exception can actually be thrown
$exceptionArray = parent::decodeGoogleException($exception);
throw new Exception($exceptionArray["message"].";".$exceptionArray["details"][0]["fieldViolations"][0]["description"], $exceptionArray["code"], $exception);
}
return $locations["locations"] ?? [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment