使用评价数据
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本教程介绍了如何列出、返回、回复和删除评价。借助 Google My Business API,您可以使用评价数据执行以下操作:
准备工作
在使用 Google My Business API 之前,您需要注册您的应用并获取 OAuth 2.0 凭据。要详细了解如何开始使用 Google My Business API,请参阅基本设置。
列出所有评价
列出某个营业地点的所有评价以批量审核评价。使用 accounts.locations.reviews.list API 返回与某个营业地点关联的所有评价。
要返回与某个营业地点关联的所有评价,请使用以下命令:
GET
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews
以下函数使用 Mybusiness.Accounts.Locations.Reviews.List
。
/**
* Returns a list of reviews.
* @param locationName Name of the location to retrieve reviews for.
* @return List<Reviews> A list of reviews.
* @throws Exception
*/
public static List<Review> listReviews(String locationName) throws Exception {
Mybusiness.Accounts.Locations.Reviews.List reviewsList =
mybusiness.accounts().locations().reviews().list(locationName);
ListReviewsResponse response = accountsList.execute();
List<Reviews> reviews = response.getReviews();
for (Reviews review : reviews) {
System.out.println(review.toPrettyString());
}
return reviews;
}
获取特定评价
按名称返回特定评价。使用 accounts.locations.reviews.get API 返回与某个营业地点关联的特定评价。
要返回特定评价,请使用以下命令:
GET
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}
以下函数使用 Mybusiness.Accounts.Locations.Reviews.Get
。
/**
* Demonstrates getting a review by name.
* @param reviewName The name (resource path) of the review to retrieve.
* @return Account The requested review.
*/
private static Review getReview(String reviewName) throws Exception {
Mybusiness.Accounts.Locations.Reviews.Get review =
mybusiness.accounts().locations().reviews().get(reviewName);
Review response = review.execute();
return response;
}
其他数据
借助 Java 客户端库,您可以查看评价实例的其他字段数据。使用以下方法可返回评价的其他相关数据:
getReviewId()
getComment()
getReviewer()
getStarRating()
getCreateTime()
getReviewReply()
获取多个营业地点的评价
获取多个营业地点的评价。使用 accounts.locations.batchGetReviews API 在单个请求中返回多个营业地点的评价。
要返回多个营业地点的评价,请使用以下命令:
POST
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations:batchGetReviews
{
"locationNames": [
string
],
"pageSize": number,
"pageToken": string,
"orderBy": string,
"ignoreRatingOnlyReviews": boolean
}
回复评价
您可以回复特定评价,如果不存在回复,也可以创建新的回复。使用 accounts.locations.reviews.updateReply API 来回复与某个营业地点关联的特定评价。
要回复特定评价,请使用以下命令:
PUT
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply
{
comment: "Thank you for visiting our business!"
}
以下函数使用 Mybusiness.accounts.locations.reviews.reply
。
/*
* Updates the reply for a location review.
* If a review does not exist, creates a new one.
* @param reviewName Name of the review being responded to.
* @param comment A string containing the review response body.
* @throws IOException
*/
private static Reply reply(String reviewName, String comment) throws IOException {
MyBusiness.Accounts.Locations.Reviews.Reply reply =
mybusiness().accounts().locations().reviews().reply(reviewName, comment);
Reply response = reviewReply.execute();
return response;
}
删除评价回复
删除针对特定评价的回复。使用 accounts.locations.reviews.deleteReply API 删除针对与某个营业地点关联的特定评价的回复。
要删除针对某条评价的特定回复,请使用以下命令:
DELETE
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply
以下函数使用 Mybusiness.Accounts.Locations.Reviews.DeleteReply
。
/**
* Demonstrates deleting a review reply by name.
* @param reviewName The name (resource path) of the review reply to delete.
* @return Account The requested review.
*/
private static DeleteReply deleteReply(String reviewName) throws Exception {
Mybusiness.Accounts.Locations.Reviews.DeleteReply toDelete =
mybusiness.accounts().locations().reviews().deleteReply(reviewName);
DeleteReply response = toDelete.execute();
return response;
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThis tutorial demonstrates how to interact with Google My Business reviews, including listing, retrieving, replying to, and deleting them using the Google My Business API.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage reviews for individual or multiple locations, retrieve specific review details (like comment, rating, reviewer), and programmatically reply to or delete review responses.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the API, ensure your application is registered and has obtained OAuth 2.0 credentials, and for reply functionality, your G Suite administrator has enabled the necessary Google services.\u003c/p\u003e\n"],["\u003cp\u003eThe tutorial provides code samples in Java and HTTP request formats for various review operations.\u003c/p\u003e\n"],["\u003cp\u003eAdditional data fields are accessible through the Java Client Library for more detailed review information.\u003c/p\u003e\n"]]],[],null,["# Work with review data\n\n\u003cbr /\u003e\n\nThis tutorial shows you how to list, return, reply, and delete a review. The\nGoogle My Business API provides you with the ability to work with review data to\nperform the following operations:\n\n- [List all reviews](#list_all_reviews).\n- [Get a specific review](#get_a_specific_review).\n- [Get reviews from multiple locations](#get_reviews_from_multiple_locations).\n- [Reply to a review](#reply_to_a_review).\n- [Delete a review reply](#delete_a_review_reply).\n\nBefore you begin\n----------------\n\nBefore you use the Google My Business API, you need to register your\napplication and obtain OAuth 2.0 credentials. For details on how to get started\nwith the Google My Business API, see\n[Basic setup](/my-business/content/basic-setup).\n\nList all reviews\n----------------\n\nList all reviews of a location to audit reviews in bulk. Use the\n[accounts.locations.reviews.list](/my-business/reference/rest/v4/accounts.locations.reviews/list)\nAPI to return all of the reviews associated with a location.\n\nTo return all reviews associated with a location, use the following:\nHTTP \n\n```\nGET\nhttps://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews\n```\nJava\n\nThe following function uses `Mybusiness.Accounts.Locations.Reviews.List`. \n\n```java\n/**\n * Returns a list of reviews.\n * @param locationName Name of the location to retrieve reviews for.\n * @return List\u003cReviews\u003e A list of reviews.\n * @throws Exception\n */\npublic static List\u003cReview\u003e listReviews(String locationName) throws Exception {\n Mybusiness.Accounts.Locations.Reviews.List reviewsList =\n mybusiness.accounts().locations().reviews().list(locationName);\n ListReviewsResponse response = accountsList.execute();\n List\u003cReviews\u003e reviews = response.getReviews();\n\n for (Reviews review : reviews) {\n System.out.println(review.toPrettyString());\n }\n return reviews;\n}\n```\n\nGet a specific review\n---------------------\n\nReturn a specific review by name. Use the\n[accounts.locations.reviews.get](/my-business/reference/rest/v4/accounts.locations.reviews/get)\nAPI to return a specific review associated with a location.\n\nTo return a specific review, use the following:\nHTTP \n\n```\nGET\nhttps://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}\n```\nJava\n\nThe following function uses `Mybusiness.Accounts.Locations.Reviews.Get`. \n\n```java\n/**\n * Demonstrates getting a review by name.\n * @param reviewName The name (resource path) of the review to retrieve.\n * @return Account The requested review.\n */\nprivate static Review getReview(String reviewName) throws Exception {\n Mybusiness.Accounts.Locations.Reviews.Get review =\n mybusiness.accounts().locations().reviews().get(reviewName);\n Review response = review.execute();\n\n return response;\n}\n```\n\n### Additional data\n\nThe Java Client Library gives you access to additional field data for review\ninstances. Use the following methods to return additional data about reviews:\n\n- `getReviewId()`\n- `getComment()`\n- `getReviewer()`\n- `getStarRating()`\n- `getCreateTime()`\n- `getReviewReply()`\n\nGet reviews from multiple locations\n-----------------------------------\n\nGet reviews from multiple locations. Use the\n[accounts.locations.batchGetReviews](https://developers.google.com/my-business/reference/rest/v4/accounts.locations/batchGetReviews)\nAPI to return reviews from multiple locations in a single request.\n\nTo return reviews from multiple locations, use the following:\nHTTP\n\n\u003cbr /\u003e\n\n```\nPOST\nhttps://mybusiness.googleapis.com/v4/accounts/{accountId}/locations:batchGetReviews\n\n{\n \"locationNames\": [\n string\n ],\n \"pageSize\": number,\n \"pageToken\": string,\n \"orderBy\": string,\n \"ignoreRatingOnlyReviews\": boolean\n}\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nReply to a review\n-----------------\n\n| **Important:** In order to use this functionality, you need to ensure that your G Suite Organization Administrator has enabled Google Search and/or Google Maps as services for your account, along with Business Profile. If you experience any issues, contact your Administrator. To learn more, see [Who is my administrator?](https://support.google.com/a/answer/6208960), [Control who can access G Suite and Google services](https://support.google.com/a/answer/182442), and [Apply policies to different users](https://support.google.com/a/topic/1227584).\n\nReply to a specific review, or create a new reply if one doesn't exist. Use the\n[accounts.locations.reviews.updateReply](/my-business/reference/rest/v4/accounts.locations.reviews/updateReply)\nAPI to reply to a specific review associated with a location.\n\nTo reply to a specific review, use the following:\nHTTP \n\n```\nPUT\nhttps://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply\n\n{\n comment: \"Thank you for visiting our business!\"\n}\n```\nJava\n\nThe following function uses `Mybusiness.accounts.locations.reviews.reply`. \n\n```java\n/*\n * Updates the reply for a location review.\n * If a review does not exist, creates a new one.\n * @param reviewName Name of the review being responded to.\n * @param comment A string containing the review response body.\n * @throws IOException\n */\nprivate static Reply reply(String reviewName, String comment) throws IOException {\n\n MyBusiness.Accounts.Locations.Reviews.Reply reply =\n mybusiness().accounts().locations().reviews().reply(reviewName, comment);\n\n Reply response = reviewReply.execute();\n\n return response;\n}\n```\n\nDelete a review reply\n---------------------\n\nDelete a reply to a specific review. Use the\n[accounts.locations.reviews.deleteReply](/my-business/reference/rest/v4/accounts.locations.reviews/deleteReply)\nAPI to delete a reply to a specific review associated with a location.\n\nTo delete a specific reply to a review, use the following:\nHTTP \n\n```\nDELETE\nhttps://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply\n```\nJava\n\nThe following function uses `Mybusiness.Accounts.Locations.Reviews.DeleteReply`. \n\n```java\n/**\n * Demonstrates deleting a review reply by name.\n * @param reviewName The name (resource path) of the review reply to delete.\n * @return Account The requested review.\n */\nprivate static DeleteReply deleteReply(String reviewName) throws Exception {\n Mybusiness.Accounts.Locations.Reviews.DeleteReply toDelete =\n mybusiness.accounts().locations().reviews().deleteReply(reviewName);\n DeleteReply response = toDelete.execute();\n\n return response;\n}\n```"]]