Reviews from Google My Business API and Google Cloud Platform

R

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.

  1. Copy the Client ID and go to the OAuth 2.0 Playground.
  2. On the right-hand side open the settings with the Gear icon.
  1. Set OAuth flow to Client-side.
  2. Select Use your own OAuth credentials.
  3. 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

  1. Click Authorise APIs and Accept when prompted.
  2. 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!

About the author

Marta Lopez

I am a content writer and I write articles on sports, news, business etc.

By Marta Lopez

Categories

Get in touch

Content and images available on this website is supplied by contributors. As such we do not hold or accept liability for the content, views or references used. For any complaints please contact adelinedarrow@gmail.com. Use of this website signifies your agreement to our terms of use. We do our best to ensure that all information on the Website is accurate. If you find any inaccurate information on the Website please us know by sending an email to adelinedarrow@gmail.com and we will correct it, where we agree, as soon as practicable. We do not accept liability for any user-generated or user submitted content – if there are any copyright violations please notify us at adelinedarrow@gmail.com – any media used will be removed providing proof of content ownership can be provided. For any DMCA requests under the digital millennium copyright act
Please contact: adelinedarrow@gmail.com with the subject DMCA Request.