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

Aleksandar Gakovic
Oct 11, 2020 · 4 min read
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

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.

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.

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

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

The Startup

Get smarter at building your thing. Join The Startup’s +786K followers.

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Aleksandar Gakovic

Written by

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

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +786K followers.

Aleksandar Gakovic

Written by

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

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +786K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store