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

Only getting 100 locations

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

Hi

 

I'm slowly having success with the Google My Business API.  Using the ServiceAccount I can get back Locations successfully, but it only gives me 100 locations even though there are more (123 I believe) in our business.

 

Is there a reason why it is only giving me 100 and what can I do to resolve this?  This is using the C# Client Library.

 

My code for retrieving the locations is briefly as follows:

AccountsResource.LocationsResource.ListRequest locationsListRequest = mbsService.Accounts.Locations.List(account.Name)
Data.ListLocationsResponse locationsResult = locationsListRequest.Execute()

 

I should point out that even getting the locations through OAuth2 Playground only gives me 100 locations too.

 

Thanks in advance,

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Shark S
July 2016

Re: Only getting 100 locations

Google Employee
# 2
Google Employee

Hi @Shark S,

 

Please note that the maximum page size is 100 when listing locations for the specified account via the Google My Business API. You should add the pageSize and pageToken query parameters to the GET request for listing all locations under the specified account if the total number of locations exceeds 100 for that account. Please make sure that the pageToken is set to the nextPageToken field value returned by a preceding call to list locations when there were more locations than could fit in the requested page size.

 

Please also make sure that you provide a consistent pageSize query parameter in the GET request because the pageSize determines the number of pages for your total results. Notice that the pageSize query parameter has a default value 100, a minimum value 1, and a maximum value 100.

 

The following is a code snippet for listing locations when including the pageSize and pageToken query parameters with the C# client library:

 // Creates and executes the request.

 var locationsListRequest = service.Accounts.Locations.List(account.Name);

 locationsListRequest.PageSize = 100;

 locationsResult = locationsListRequest.Execute();

 

 if (locationsResult != null)

 {

   PrintLocations(locationsResult.Locations);

   while (locationsResult.NextPageToken != null)

   {

     locationsListRequest.PageToken = locationsResult.NextPageToken;

     locationsResult = locationsListRequest.Execute();

     PrintLocations(locationsResult.Locations);

   }

 }

 else

 {

   Console.WriteLine("Account {0} has no locations.", account.Name);

 }

 

Thanks,

Terry

Re: Only getting 100 locations

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks Terry, that has worked a treat :smileyhappy: