My Business
2.4K members online now
2.4K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

PHP Samples

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Is there anywhere a Documentation for PHP, with Samples?

I Try to list more than 100 Locations or try to use some Filters, but i found no samples to do that

 

Sample:

$test= $gmbService->accounts_locations->listAccountsLocations('accounts/xxxxxx', array('filter' => 'storeCode=%033%'));

if (is_object($test)) {
$count = 0;
foreach($test['modelData']['locations'] as $testLocal) {
$gName = $testLocal['name'];
$count ++;

echo $testLocal['storeCode'].' | '.$testLocal['locationName'].'<br>';
}

echo 'Count: '.$count;
//*/
}

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Andreas C
September 2016

Re: PHP Samples

Google Employee
# 2
Google Employee

Hi @Andreas C,

 

We don’t offer a sample app for PHP. At your request, I’m providing the following code snippet for listing all paginated locations by including the pageSize and pageToken query parameters with the PHP client library:

         try {

           $listLocationsResponse = $locations->listAccountsLocations($account->name, array('pageSize' => 100));

           printLocations($listLocationsResponse->getLocations());

           while ($listLocationsResponse->nextPageToken) {

             $listLocationsResponse = $locations->listAccountsLocations($account->name, array('pageSize' => 100, 'pageToken' => $listLocationsResponse->nextPageToken));

             printLocations($listLocationsResponse->getLocations());

           }

         } catch (Exception $e) {

           print "Caught exception: <br />" . $e->getMessage() . "<br />";

         }

 

The storeCode field is not a valid filter field of a restriction in a filter expression when listing locations via the API. You can find a list of valid filter fields and example usage in our Work with Location Data Guide. The following is another code snippet for listing all locations and using filters to limit the results with the PHP client library:

             try {

               $listLocationsResponse = $locations->listAccountsLocations($account->name, array('filter' => "(location.categories=\"gcid:software_company\" OR location.categories=\"gcid:corporate_office\") AND location.labels:\"Recently opened\" AND location.labels:\"High-traffic\""));

               printLocations($listLocationsResponse->getLocations());

             } catch (Exception $e) {

               print "Caught exception: <br />" . $e->getMessage() . "<br />";

             }

 

I hope this helps you implement your application.

 

Thanks,

Terry

Re: PHP Samples

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Thanx a lot, that helps me, but a better documentation for PHP would make develop much easier