Created
October 26, 2023 19:37
-
-
Save SudoPlz/56f58cdd77355935e3de461ee92c2ddb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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