I want to know how can I use GMB API to fetch reviews. According to google documentation we have to make a GET request to https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews
But what is meant by {name=accounts/*/locations/*} and from where we can get the value of accounts & locations.
Also this requires OAuth 2.0. If I get a access_token then GET request will be like this:-
https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews?access_token=token
This is very confusing. Can somebody tell me how to use GMB API correctly to fetch google reviews.
Using Google OAuth 2 Playground
For testing acquisition of Google reviews
- Create a project
- Console.cloud.google.com
- Sign in as {projectowner}@google.com
- Select a project from the dropdown in the header or click new project
- Go to APIs & Services in the left menu
- Enable the Google My Business API; this requires validation by Google and may take a couple of days. They will email you.
- Go to developers.google.com/oauthplayground
- Using the settings gear, set OAuth flow to Client-side and click Use your own OAuth credentials
- Get the client id from console.developers.google.com/apis and paste it in
- Put this into scope: https://www.googleapis.com/auth/plus.business.manage and authorize it with {projectowner}@gmail.com
- Exchange auth code for token
- To get the account name:
- Set Request URI to https://mybusiness.googleapis.com/v4/accounts and send a Get request
- Copy the entire string value at “name”: not including quotes; it may be 20+ numeric digits
- To get location names:
- Set Request URI to https://mybusiness.googleapis.com/v4/accounts/{paste account name here}/locations where {paste ... here} is the account name you copied
- The returned JSON contains all of your locations
- Copy the location names including quotes and commas to a temporary holding document; they will be used in a JSON array in the next step
- To get multiple locations’ reviews
a. Set Request URI to https://mybusiness.googleapis.com/v4/accounts/{account name here}/locations:batchGetReviews and the Method to Post
b. Set Request Body to
{
"locationNames": [
"accounts/999999999999999999999/locations/88888888888888888888",
"accounts/999999999999999999999/locations/77777777777777777777",
.
.
.
"accounts/999999999999999999999/locations/11111111111111111111"
],
"pageSize": 200,
"orderBy": "updateTime desc",
"ignoreRatingOnlyReviews": false
}
using the account names you saved from the location JSON for each line of the array
- If you have more than 200 total reviews you will have to add "pageToken": string into the JSON body where string is a value returned in the preceding POST.