AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

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

GMB API reviews handling

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

Hi ,

I'm having some questions about the review handling using GMB API.

 

1. I got more numbers of reviews in my location all these years, using GMB API will retrieve from the first review to till date.

2. Retrieve the replied reviews and not replied reviews separately using GMB API from my location. 

3. Retrieve the reviews based on the star rating , based on dates.

 

I was analyzing the Google My Business API , the above mentioned points i came across. Can you guide me the steps to be followed using GMB API.

 

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Mahender S
September 2016

Re: GMB API reviews handling

Google Employee
# 2
Google Employee

Hi @Mahender S,

 

  1. You can only fetch a maximum of 200 reviews per page. Therefore, you should specify the pageSize and pageToken query parameters to paginate the reviews when listing all reviews for the specified location. You should provide a consistent pageSize query parameter because the pageSize determines the number of pages for your total results. Please make sure that the pageToken is set to the nextPageToken field value returned by a preceding call to list reviews when there were more reviews than could fit in the requested pageSize. Here is a code snippet for listing all reviews and including the pageSize and pageToken query parameters with the C# client library:

         // Lists all reviews with the pageSize and pageToken.

         var reviewsListRequest = service.Accounts.Locations.Reviews.List(location.Name);

         reviewsListRequest.PageSize = 200;

         ListReviewsResponse reviewsResult = reviewsListRequest.Execute();

         

         if (reviewsResult != null)

         {

             PrintReviews(reviewsResult.Reviews);

             while (reviewsResult.NextPageToken != null)

             {

                 reviewsListRequest.PageToken = reviewsResult.NextPageToken;

                 reviewsResult = reviewsListRequest.Execute();

                 PrintReviews(reviewsResult.Reviews);

             }

         }

         else

         {

             Console.WriteLine("Location {0} has no reviews.", location.Name);

         }

 

  1. You can use a loop to check whether the comment field of the ReviewReply object within a Review object is equal to null to see if a review has a reply. Here is a code snippet for printing all reviews that have been replied with the C# client library:

         /// <summary>Prints reviews.</summary>

         public static void PrintReviews(IList<Review> reviews)

         {

             // Prints all reviews that have been replied.

             int i = 0;

             foreach (Review review in reviews)

             {

                 if (review.ReviewReply.Comment != null)

                 {

                     Console.Write((++i) + "):");

                     PrintReview(review);

                 }

             }

         }

 

  1. You can use a loop to filter and show only reviews with a specific starRating and createTime or updateTime. Here is a code snippet for printing all reviews filtered by the starRating and updateTime with the C# client library:

         // Prints all reviews filtered by the starRating and updateTime.

         DateTime defaultDateTime = new DateTime(2016, 8, 25, 0, 0, 0);

         int i = 0;

         foreach (Review review in reviews)

         {

             DateTime dateTime = Convert.ToDateTime(review.UpdateTime.ToString());

             // Displays the review if it has five-star rating and has been updated after 8/25/2016 12:00:00 AM

             if (review.StarRating == "FIVE" && DateTime.Compare(defaultDateTime, dateTime) < 0)

             {

                 Console.Write((++i) + "):");

                 PrintReview(review);

             }

         }

 

Thanks,

Terry

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Mahender S
September 2016

Re: GMB API reviews handling

Google Employee
# 2
Google Employee

Hi @Mahender S,

 

  1. You can only fetch a maximum of 200 reviews per page. Therefore, you should specify the pageSize and pageToken query parameters to paginate the reviews when listing all reviews for the specified location. You should provide a consistent pageSize query parameter because the pageSize determines the number of pages for your total results. Please make sure that the pageToken is set to the nextPageToken field value returned by a preceding call to list reviews when there were more reviews than could fit in the requested pageSize. Here is a code snippet for listing all reviews and including the pageSize and pageToken query parameters with the C# client library:

         // Lists all reviews with the pageSize and pageToken.

         var reviewsListRequest = service.Accounts.Locations.Reviews.List(location.Name);

         reviewsListRequest.PageSize = 200;

         ListReviewsResponse reviewsResult = reviewsListRequest.Execute();

         

         if (reviewsResult != null)

         {

             PrintReviews(reviewsResult.Reviews);

             while (reviewsResult.NextPageToken != null)

             {

                 reviewsListRequest.PageToken = reviewsResult.NextPageToken;

                 reviewsResult = reviewsListRequest.Execute();

                 PrintReviews(reviewsResult.Reviews);

             }

         }

         else

         {

             Console.WriteLine("Location {0} has no reviews.", location.Name);

         }

 

  1. You can use a loop to check whether the comment field of the ReviewReply object within a Review object is equal to null to see if a review has a reply. Here is a code snippet for printing all reviews that have been replied with the C# client library:

         /// <summary>Prints reviews.</summary>

         public static void PrintReviews(IList<Review> reviews)

         {

             // Prints all reviews that have been replied.

             int i = 0;

             foreach (Review review in reviews)

             {

                 if (review.ReviewReply.Comment != null)

                 {

                     Console.Write((++i) + "):");

                     PrintReview(review);

                 }

             }

         }

 

  1. You can use a loop to filter and show only reviews with a specific starRating and createTime or updateTime. Here is a code snippet for printing all reviews filtered by the starRating and updateTime with the C# client library:

         // Prints all reviews filtered by the starRating and updateTime.

         DateTime defaultDateTime = new DateTime(2016, 8, 25, 0, 0, 0);

         int i = 0;

         foreach (Review review in reviews)

         {

             DateTime dateTime = Convert.ToDateTime(review.UpdateTime.ToString());

             // Displays the review if it has five-star rating and has been updated after 8/25/2016 12:00:00 AM

             if (review.StarRating == "FIVE" && DateTime.Compare(defaultDateTime, dateTime) < 0)

             {

                 Console.Write((++i) + "):");

                 PrintReview(review);

             }

         }

 

Thanks,

Terry

Re: GMB API reviews handling

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hello Terry,
Thanks for the solution and guidance.

Best Regards,
Mahender S.

GMB API reviews handling

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Hi Mahender, i am newly working with Google My Business API can you please Explain me what i need to do, mySkypeID: sravan.bookmeds@outlook.com . please send me request i need to discuss with you..