Using Google Cloud Platform and Google My Business API to Obtain Location Reviews

Aleksandar Gakovic
The Startup
Published in
4 min readOct 11, 2020
GET
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews
Photo by Nathan Dumlao on Unsplash

I began my journey into obtaining google reviews last week and was surprised to find that it wasn’t as straightforward as I thought it would be. I write this article to help others who wish to obtain google review data (and other data related to location).
Getting Started — Permissions
Enabling and Using the Google My Business API

Getting Started — Permissions

Make sure you have access both to the project account on the Google Cloud
Platform
(GCP) and to the business account on Google My Business (GMB). As a data scientist volunteering for the company, I had to request editing permissions to the GCP project, and manager permissions to the GMB account.

This is extremely important, you need access to both platforms for the same project or the API will not retrieve the business data.

At this point, the only other prerequisite is to make sure that access has been requested and given for the GMB API. Typically the project owner does this but it is possible if you now have editing access on the GCP.

  1. Go to Google API Console and select the relevant project.
  2. Determine your Project ID in the Project ID column.
  3. Fill out and submit an access request form
  4. Check your email for follow up validation.

Enabling and using the API

Great stuff! We’re getting there, but the rabbit hole only deepens from here on. We need to enable Google My Business API. This can be done by following the basic setup guide in the GMB API docs or manually going to the API library in the Google API console:

  1. Select the relevant project if prompted.
  2. If the GMB API is not available in the list search for it.
  3. Select it and click the Enable button.

Now that the API is enabled we can access data like reviews and simple insights into the business that Google kindly provides.

OAuth and using the API

A quick way to access these data is to jump into the OAuth 2.0 Playground. We can make a request for review there as well as business insights but first, we will have to authorise access with OAuth. You can also follow along in the ‘Make a simple HTTP request’ section from the get started guide.

  1. In the Google API Console open your project and navigate to Credentials.
    - Select OAuth client ID from the create credentials drop-down list.
    - Select Web Application for the application type.
    - Use the following as a redirect URI:
https://developers.google.com/oauthplayground

You can now click Create.

2. Copy the Client ID and go to the OAuth 2.0 Playground.
3. On the right-hand side open the settings with the Gear icon.
- Set OAuth flow to Client-side.
- Select Use your own OAuth credentials.
- Paste in your OAuth client ID.

4. Exit the options and Input your own scopes field in “Step1” use the following scope:

https://www.googleapis.com/auth/business.manage

5. Click Authorise APIs and Accept when prompted.
6. Finally, under “Step2 — configure request to API”, try the following URI in the Request URI field:

https://mybusiness.googleapis.com/v4/accounts

The above URI — Uniform resource identifier is the basc request from which you can access the accountId and locationId necessary for review data. Using the above request will give you access to the accountId which is a number.

Then inputting that number after accounts will let you access the location data if there are any for that account. The accountId used below is for example only:

https://mybusiness.googleapis.com/v4/accounts/0123456789/locations

You can find the locationId with the above request, substituting your accountId for the number you see above, of course.

Finally using both complement id’s (without the curly braces ‘{}’) and adding reviews at the end will allow you to hit the reviews end point and access all reviews:

https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews

If you wish to change the number of reviews retrieved you can add `?pageSize=n` to the end as a query parameter. You must change ’n’ to the number of reviews you wish to return per page (Maximum 50).

https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews?pageSize=10

If there are more than 50 reviews, you will be able to access the next page of reviews using a pageToken (a string) which you will find at the bottom of your first request result. Simply add it as a query parameter to the end of a new request:

https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews?pageToken=AS1sd1E"£$ae8a9s0df81

Please note the ‘pageToken=AS1sd1E”£$ae8a9s0df81’ found above will not work as it was personal to my get request when I wrote this article. You can find yours at the bottom of your get request. See the Google My Business locations.reviews.list documentation for more.

For location insights including how many times certain items and resources were clicked and how many times posts or resources were viewed, use the following request and change the {accountId} to your own as above.

https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations:reportInsights

Conclusion

I really hope this helped you! I had a bit of difficulty working out which numbers I needed and how to obtain them. There is so much documentation it can be easy to get overwhelmed. So I place it all in one article hopefully to make things more streamlined for people in the future.

Thank you for Reading!

References

  1. Google Cloud console — Homepage
  2. Google MyBusiness — Homepage
  3. Prerequisites for GMB API — Get Started Guide
  4. GMB API Access request form
  5. Requests library — documentation
  6. Working with Review Data — GMB API documentation
  7. OAuth 2.0 Playground — quick access to the data.
  8. Make a simple HTTP Request — Get started guide GMB API
  9. Query Parameters — Working with Review data GMP API documentation
  10. Google MyBusiness Method: locations.reviews.list docs

--

--

Aleksandar Gakovic
The Startup

Practicing Data Scientist. Interested in Games, Gamification, Ocean Sciences, Music, Biology.