ผสานรวมรีวิวในแอป (Unity)
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คู่มือนี้จะอธิบายวิธีผสานรวมรีวิวในแอปในแอปของคุณโดยใช้ Unity
เรามีคู่มือการผสานรวมแยกต่างหากสำหรับกรณีที่คุณใช้ Kotlin หรือ Java, โค้ดเนทีฟ หรือ Unreal Engine
ภาพรวมของ Unity SDK
Play In-App Review API เป็นส่วนหนึ่งของตระกูล Play Core SDK API สำหรับ Unity มีคลาส ReviewManager
เพื่อขอและเปิดใช้งานขั้นตอนโดยใช้เมธอด RequestReviewFlow
และ LaunchReviewFlow
หลังจากส่งคำขอแล้ว แอปจะตรวจสอบสถานะคำขอได้โดยใช้ ReviewErrorCode
ตั้งค่าสภาพแวดล้อมการพัฒนา
OpenUPM-CLI
หากติดตั้ง OpenUPM CLI แล้ว คุณจะติดตั้งรีจิสทรี OpenUPM ได้ด้วยคำสั่งต่อไปนี้
openupm add com.google.play.review
OpenUPM
เปิดการตั้งค่าเครื่องมือจัดการแพ็กเกจโดยเลือกตัวเลือกเมนู Unity
แก้ไข > การตั้งค่าโปรเจ็กต์ > เครื่องมือจัดการแพ็กเกจ
เพิ่ม OpenUPM เป็นรีจิสทรีที่มีขอบเขตไปยังหน้าต่างตัวจัดการแพ็กเกจ โดยทำดังนี้
Name: package.openupm.com
URL: https://package.openupm.com
Scopes: com.google.external-dependency-manager
com.google.play.common
com.google.play.core
com.google.play.review
เปิดเมนูเครื่องมือจัดการแพ็กเกจโดยเลือกตัวเลือกเมนู Unity หน้าต่าง > เครื่องมือจัดการแพ็กเกจ
ตั้งค่าเมนูแบบเลื่อนลงของขอบเขตบัญชีดูแลจัดการเพื่อเลือกรีจิสทรีของฉัน
เลือกแพ็กเกจปลั๊กอิน Google Play Integrity สำหรับ Unity จากรายการแพ็กเกจ แล้วกดติดตั้ง
นําเข้าจาก GitHub
ดาวน์โหลดรุ่นล่าสุดของ .unitypackage
จาก GitHub
นําเข้าไฟล์ .unitypackage
โดยเลือกตัวเลือกเมนู Unity
ชิ้นงาน > นําเข้าแพ็กเกจ > แพ็กเกจที่กําหนดเอง และนําเข้ารายการทั้งหมด
สร้าง ReviewManager
สร้างอินสแตนซ์ของ ReviewManager
ที่จัดการการสื่อสารระหว่างแอปของคุณกับ Google Play API
using Google.Play.Review;
// Create instance of ReviewManager
private ReviewManager _reviewManager;
// ...
_reviewManager = new ReviewManager();
ขอออบเจ็กต์ ReviewInfo
ทำตามคำแนะนำเกี่ยวกับเวลาที่ควรขอรีวิวในแอปเพื่อระบุจุดที่เหมาะสมในเส้นทางของผู้ใช้แอปเพื่อแจ้งให้ผู้ใช้เขียนรีวิว (เช่น หลังจากที่ผู้ใช้ปิดหน้าจอสรุปเมื่อจบด่านในเกม) เมื่อแอปของคุณใกล้ถึงจุดใดจุดหนึ่งเหล่านี้ ให้ใช้อินสแตนซ์ ReviewManager
เพื่อสร้างการดำเนินการแบบแอสซิงค์ ดังที่แสดงในตัวอย่างต่อไปนี้
var requestFlowOperation = _reviewManager.RequestReviewFlow();
yield return requestFlowOperation;
if (requestFlowOperation.Error != ReviewErrorCode.NoError)
{
// Log error. For example, using requestFlowOperation.Error.ToString().
yield break;
}
_playReviewInfo = requestFlowOperation.GetResult();
หากการเรียกสำเร็จ API จะแสดงออบเจ็กต์ PlayReviewInfo
ที่แอปของคุณต้องใช้เพื่อเปิดใช้ขั้นตอนการรีวิวในแอป ในตัวอย่างนี้ การเรียกใช้เกิดขึ้นภายใน Coroutine เพื่อดำเนินการแบบแอสซิงค์ (การดำเนินการนี้จะไม่บล็อกเทรดหลัก) เนื่องจากมีการเรียกใช้แบบไม่พร้อมกัน จึงอาจใช้เวลาถึง 2-3 วินาที ดังนั้นแอปของคุณควรเรียกใช้ก่อนที่จะถึงจุดใน FLow ของผู้ใช้ที่คุณต้องการแสดงรีวิวในแอป
เปิดขั้นตอนการรีวิวในแอป
หลังจากแอปได้รับอินสแตนซ์ PlayReviewInfo
แล้ว ก็จะเปิดขั้นตอนการตรวจสอบในแอปได้ โปรดทราบว่าออบเจ็กต์ PlayReviewInfo
จะใช้งานได้เพียงระยะเวลาหนึ่งเท่านั้น ดังนั้นแอปของคุณไม่ควรรอนานเกินไปก่อนที่จะเปิดใช้งานโฟลว์
var launchFlowOperation = _reviewManager.LaunchReviewFlow(_playReviewInfo);
yield return launchFlowOperation;
_playReviewInfo = null; // Reset the object
if (launchFlowOperation.Error != ReviewErrorCode.NoError)
{
// Log error. For example, using launchFlowOperation.Error.ToString().
yield break;
}
// The flow has finished. The API does not indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, we continue our app flow.
ขั้นตอนถัดไป
ทดสอบขั้นตอนการรีวิวในแอปของแอปเพื่อยืนยันว่าการผสานรวมทํางานอย่างถูกต้อง
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Integrate in-app reviews (Unity)\n\nThis guide describes how to integrate in-app reviews in your app using Unity.\nThere are separate integration guides for if you are using [Kotlin or Java](/guide/playcore/in-app-review/kotlin-java),\n[native code](/guide/playcore/in-app-review/native) or [Unreal Engine](/guide/playcore/in-app-review/unreal-engine).\n\nUnity SDK overview\n------------------\n\nThe Play In-App Review API is part of [Play Core SDK](/reference/com/google/android/play/core/release-notes) family. The API for\nUnity offers a [`ReviewManager`](/reference/unity/class/Google/Play/Review/ReviewManager) class to request and launch the flow using\nthe [`RequestReviewFlow`](/reference/unity/class/Google/Play/Review/ReviewManager#requestreviewflow) and [`LaunchReviewFlow`](/reference/unity/class/Google/Play/Review/ReviewManager#launchreviewflow) methods. After a\nrequest is made, your app can check the status of the request using\n[`ReviewErrorCode`](/reference/unity/namespace/Google/Play/Review#reviewerrorcode).\n\nSet up your development environment\n-----------------------------------\n\n### OpenUPM-CLI\n\nIf you have the [OpenUPM CLI](https://github.com/openupm/openupm-cli#installation)\ninstalled you can install the OpenUPM registry with the following command: \n\n openupm add com.google.play.review\n\n### OpenUPM\n\n1. Open the [package manager settings](https://docs.unity3d.com/Manual/class-PackageManager.html)\n by selecting the Unity menu option\n **Edit \\\u003e Project Settings \\\u003e Package Manager**.\n\n2. Add OpenUPM as a scoped registry to the Package Manager window:\n\n Name: package.openupm.com\n URL: https://package.openupm.com\n Scopes: com.google.external-dependency-manager\n com.google.play.common\n com.google.play.core\n com.google.play.review\n\n3. Open the [package manager menu](//docs.unity3d.com/Manual/upm-ui-install.html) by selecting the Unity\n menu option **Window \\\u003e Package Manager**.\n\n4. Set the manager scope drop-down to select **My Registries**.\n\n5. Select the **Google Play Integrity plugin for Unity** package from the\n package list and press **Install**.\n\n### Import from GitHub\n\n1. Download the latest [`.unitypackage`](//github.com/google/play-in-app-reviews-unity/releases/latest)\n release from GitHub.\n\n2. Import the `.unitypackage` file by selecting the Unity menu option\n **Assets \\\u003e Import package \\\u003e Custom Package** and importing all items.\n\n| **Note:** By downloading and using Google Play Unity Plugins, you agree to the [Play Core Software Development Kit Terms of Service](/guide/playcore#license).\n\nCreate the ReviewManager\n------------------------\n\nCreate an instance of [`ReviewManager`](/reference/unity/class/Google/Play/Review/ReviewManager) that handles communication between\nyour app and the Google Play API. \n\n using Google.Play.Review;\n\n // Create instance of ReviewManager\n private ReviewManager _reviewManager;\n // ...\n _reviewManager = new ReviewManager();\n\nRequest a ReviewInfo object\n---------------------------\n\nFollow the guidance about [when to request in-app reviews](/guide/playcore/in-app-review#when-to-request) to determine good\npoints in your app's user flow to prompt the user for a review (for example,\nafter a user dismisses the summary screen at the end of a level in a game). When\nyour app gets close one of these points, use the [`ReviewManager`](/reference/unity/class/Google/Play/Review/ReviewManager) instance\nto create an async operation, as shown in the following example: \n\n var requestFlowOperation = _reviewManager.RequestReviewFlow();\n yield return requestFlowOperation;\n if (requestFlowOperation.Error != ReviewErrorCode.NoError)\n {\n // Log error. For example, using requestFlowOperation.Error.ToString().\n yield break;\n }\n _playReviewInfo = requestFlowOperation.GetResult();\n\nIf the call is successful, the API returns the [`PlayReviewInfo`](/reference/unity/class/Google/Play/Review/PlayReviewInfo) object\nthat your app needs to launch the in-app review flow. In the example, the call\nis made inside a [coroutine](https://docs.unity3d.com/Manual/Coroutines.html)\nto perform the async operation (this does not block the Main thread). Because\nthe call is made asynchronously, it might take up to a couple of seconds, so\nyour app should make the call before your app reaches the point in your user\nflow where you want to show the in-app review.\n\nLaunch the in-app review flow\n-----------------------------\n\nAfter your app receives the [`PlayReviewInfo`](/reference/unity/class/Google/Play/Review/PlayReviewInfo) instance, it can launch the\nin-app review flow. Note that the `PlayReviewInfo` object is only valid for a\nlimited amount of time, so your app should not wait too long before launching a\nflow. \n\n var launchFlowOperation = _reviewManager.LaunchReviewFlow(_playReviewInfo);\n yield return launchFlowOperation;\n _playReviewInfo = null; // Reset the object\n if (launchFlowOperation.Error != ReviewErrorCode.NoError)\n {\n // Log error. For example, using launchFlowOperation.Error.ToString().\n yield break;\n }\n // The flow has finished. The API does not indicate whether the user\n // reviewed or not, or even whether the review dialog was shown. Thus, no\n // matter the result, we continue our app flow.\n\nNext steps\n----------\n\n[Test your app's in-app review flow](/guide/playcore/in-app-review/test) to verify that your integration is\nworking correctly."]]