Định cấu hình quyền truy cập vào Google Cloud Search API
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bạn phải định cấu hình quyền truy cập vào Google Cloud Search API thì mới có thể sử dụng API này một cách trực tiếp hoặc thông qua một SDK. Tài liệu này trình bày các bước cần thiết để sử dụng API REST của Google Cloud Search.
1. Tạo một dự án API
Để bật API này, trước tiên bạn phải tạo một dự án trên Google Cloud. Dự án này là cơ sở để tạo, bật và sử dụng tất cả các dịch vụ của Google Cloud, bao gồm cả việc quản lý API, bật tính năng thanh toán, thêm và xoá cộng tác viên, cũng như quản lý quyền.
Ở đầu trang, hãy nhấp vào arrow_drop_down ở bên phải "Google Cloud Console". Một hộp thoại liệt kê các dự án hiện tại sẽ xuất hiện.
Nhấp vào DỰ ÁN MỚI. Màn hình "Dự án mới" sẽ xuất hiện.
Nhập tên dự án vào trường Tên dự án.
(không bắt buộc) Nhấp vào Chỉnh sửa để chỉnh sửa mã dự án. Bạn không thể thay đổi mã dự án sau khi tạo dự án, vì vậy, hãy chọn một mã dự án đáp ứng nhu cầu của bạn trong suốt thời gian tồn tại của dự án.
Để duyệt xem các vị trí cho dự án, hãy nhấp vào DUYỆT XEM.
Nhấp vào một vị trí cho dự án của bạn rồi nhấp vào Chọn.
Nhấp vào Tạo. Bảng điều khiển sẽ chuyển đến trang Trang tổng quan. Dự án sẽ được tạo trong vòng vài phút.
Để biết thêm thông tin về cách tạo và quản lý dự án, hãy tham khảo bài viết Tạo và quản lý dự án.
2. Bật API
Bạn cần bật API Google Cloud Search và tạo một tài khoản dịch vụ để lấy thông tin xác thực.
Để đảm bảo bạn đang ở dự án mới tạo, hãy nhấp vào biểu tượng arrow_drop_down ở bên phải biểu ngữ Google Cloud Console rồi chọn dự án bạn vừa tạo.
Nhấp vào BẬT API VÀ DỊCH VỤ. Trang "Chào mừng bạn đến với Thư viện API" sẽ xuất hiện.
Trong Google Cloud Console, hãy nhấp vào Thông tin xác thực trong trình đơn điều hướng bên trái. Trang Thông tin đăng nhập sẽ xuất hiện.
Trong danh sách thả xuống Tạo thông tin xác thực, hãy chọn Tài khoản dịch vụ. Trang "Tạo tài khoản dịch vụ" sẽ xuất hiện.
Nhập tên vào trường Tên tài khoản dịch vụ.
(không bắt buộc) Chỉnh sửa mã tài khoản dịch vụ.
Nhấp vào Tạo. Màn hình "Quyền của tài khoản dịch vụ" sẽ xuất hiện.
Nhấp vào Tiếp tục. Màn hình "Cấp cho người dùng quyền truy cập vào tài khoản dịch vụ này" sẽ xuất hiện.
Nhấp vào TẠO KHOÁ rồi nhấp vào Xong. Hộp thoại "Khoá riêng tư đã lưu vào máy tính của bạn" sẽ xuất hiện và một bản sao của khoá riêng tư sẽ tải xuống máy tính của bạn.
Nhấp vào Trình đơn điều hướng ở bên trái biểu ngữ Google Cloud Console.
Nhấp vào IAM và Quản trị > Tài khoản dịch vụ.
Trong danh sách, ở mục "Mã tài khoản dịch vụ", hãy ghi lại địa chỉ email được tạo để xác định tài khoản dịch vụ mà bạn đã định cấu hình. Địa chỉ email này được dùng khi thêm một nguồn dữ liệu vào Cloud Search.
5. Khởi chạy tính năng hỗ trợ bên thứ ba
Trước khi có thể gọi bất kỳ API Cloud Search nào khác, bạn phải khởi động chế độ hỗ trợ bên thứ ba cho Google Cloud Search.
Cách khởi động tính năng hỗ trợ bên thứ ba cho Cloud Search:
Dự án nền tảng Cloud Search của bạn chứa thông tin xác thực tài khoản dịch vụ.
Tuy nhiên, để khởi tạo tính năng hỗ trợ bên thứ ba, bạn phải tạo thông tin đăng nhập ứng dụng web. Để biết hướng dẫn về cách tạo thông tin đăng nhập cho ứng dụng web, hãy tham khảo bài viết Tạo thông tin đăng nhập.
Sau khi hoàn tất bước này, bạn sẽ có một tệp mã ứng dụng khách và khoá bí mật của ứng dụng.
Nhấp vào phần cài đặt rồi đánh dấu vào Sử dụng thông tin xác thực của riêng bạn.
Nhập mã ứng dụng khách và mật khẩu ứng dụng khách từ bước 1.
Nhấp vào Close (Đóng).
Trong trường phạm vi, hãy nhập https://www.googleapis.com/auth/cloud_search.settings rồi nhấp vào Uỷ quyền. OAuth 2 Playground trả về một mã uỷ quyền.
Nhấp vào Đổi mã uỷ quyền lấy mã thông báo. Một mã thông báo sẽ được trả về.
Để khởi chạy tính năng hỗ trợ bên thứ ba cho Cloud Search, hãy sử dụng lệnh curl sau. Hãy nhớ thay thế [YOUR_ACCESS_TOKEN] bằng mã thông báo nhận được ở bước 2.
Sau đây là một số bước tiếp theo bạn có thể thực hiện:
Nếu dự định sử dụng Google Cloud Search với một kho lưu trữ dữ liệu không phải của Google, chẳng hạn như Microsoft® SharePoint®, bạn phải tạo một nguồn dữ liệu. Để biết hướng dẫn về cách thêm nguồn dữ liệu, hãy tham khảo bài viết Thêm nguồn dữ liệu vào tính năng tìm kiếm.
Sau khi thiết lập nguồn dữ liệu, bạn có thể tạo và đăng ký giản đồ để xác định cách Google Cloud Search sẽ trình bày dữ liệu trong kho lưu trữ.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[],[],null,["# Configure access to the Google Cloud Search API\n\nYou must configure access to the Google Cloud Search API before you can\nuse this API either directly or through an SDK. This document\ncovers the steps required to use the Google Cloud Search API REST API.\n\n1. Create an API project\n------------------------\n\nTo enable the API, you must first create an Google Cloud project. This\nproject forms the basis for creating, enabling, and using all Google Cloud\nservices, including managing APIs, enabling billing, adding and\nremoving collaborators, and managing permissions.\n\n1. Open the [Google Cloud console](https://console.cloud.google.com/apis/dashboard).\n\n2. At the top of the page, click\n arrow_drop_down\n to the right of \"Google Cloud Console.\" A dialog listing current projects\n appears.\n\n3. Click **NEW PROJECT**. The \"New Project\" screen appears.\n\n4. Enter a project name in the **Project Name** field.\n\n5. (optional) Click **Edit** to edit the Project ID. The project ID can't be\n changed after the project is created, so choose an\n ID that meets your needs for the lifetime of the project.\n\n6. To browse locations for the project, click **BROWSE**.\n\n7. Click on a location for your project and click **Select**.\n\n8. Click **Create**. The console navigates to the Dashboard page. The project\n is created within a few minutes.\n\nFor further information on creating and managing projects, refer to\n[Creating and Managing Projects](https://support.google.com/cloud#topic=6158848).\n\n2. Enable the API\n-----------------\n\nYou need to enable the Google Cloud Search API and create a service account to\nobtain credentials.\n\n1. To ensure you are on the newly created project, click the arrow_drop_down icon to the right of the Google Cloud console banner and select your newly-created project.\n2. Click **ENABLE APIS AND SERVICES**. The \"Welcome to API Library\" page appears.\n3. Navigate to the [Google Cloud Search API](https://console.cloud.google.com/apis/api/cloudsearch.googleapis.com).\n4. Click **Enable**. The \"Overview\" page appears.\n\nFor further information on enabling and disabling APIs, refer to\n[Manage APIs in the Google Cloud console](https://support.google.com/cloud/answer/6326510)\n| **Note:** Different Cloud Search APIs require different accounts to execute (admin, service, and user). For further information, refer to the [reference documentation](/workspace/cloud-search/docs/reference) for the method you want to call.\n\n3. Create service account credentials\n-------------------------------------\n\n1. In the [Google Cloud console](https://console.cloud.google.com/apis/library), click **Credentials** in the left navigation. The Credential page appears.\n2. From the **Create credentials** drop-down list, select **Service account**. The \"Create service account\" page appears.\n3. Enter a name in the **Service account name** field.\n4. (optional) Edit the service account ID.\n5. Click **Create**. A \"Service account permissions\" screen appears.\n6. Click **Continue**. A \"Grant users access to this service account\" screen appears.\n7. Click **CREATE KEY** and click **Done**. A \"Private key saved to your computer\" dialog appears and a copy of the private key downloads to your computer.\n8. Click **Close**.\n\nFor further information on service accounts, refer to\n[Service accounts, web applications, and installed applications](https://support.google.com/cloud/answer/6158849#serviceaccounts)\n\n4. Identify email address\n-------------------------\n\n1. From the [Google Cloud console](https://console.cloud.google.com/apis/dashboard), select the project you created at the top of the page.\n2. Click the Navigation menu to the left of the Google Cloud console banner.\n3. Click **IAM and Admin** \\\u003e **Service accounts**.\n4. In the list, under \"Service account ID,\" make note of the generated email address that identifies the service account you configured. This email address is used when adding a data source to Cloud Search.\n\n5. Initialize third-party support\n---------------------------------\n\nBefore you can call any other Cloud Search APIs, you must initialize third-party\nsupport for Google Cloud Search.\n| **Note:** If you successfully executed the Cloud Search tutorial, you have already initialized third-party support for Cloud Search and can skip this step.\n\nTo initialize third-party support for Cloud Search:\n\n1. Your Cloud Search platform project contains service account credentials.\n However, for the sake of initializing third-party support, you must create web\n application credentials. For instructions on how to create web application\n credentials, refer to\n [Create credentials](/workspace/guides/create-credentials).\n Upon completing this step, you should have a client ID and client secret file.\n\n2. Use\n [Google's OAuth 2 playground](https://developers.google.com/oauthplayground/)\n to obtain an access token:\n\n 1. Click settings and check **User your own auth credentials**.\n 2. Enter the client ID and client secret from step 1.\n 3. Click **Close**.\n 4. In the scopes field, type `https://www.googleapis.com/auth/cloud_search.settings` and click **Authorize**. The OAuth 2 playground returns an authorization code.\n 5. Click **Exchange authorization code for tokens**. A token is returned.\n3. To initialize third-party support for Cloud Search, use the following curl\n command. Be sure to substitute `[YOUR_ACCESS_TOKEN]` with the token obtained in\n step 2.\n\n curl --request POST \\\n 'https://cloudsearch.googleapis.com/v1:initializeCustomer' \\\n --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \\\n --header 'Accept: application/json' \\\n --header 'Content-Type: application/json' \\\n --data '{}' \\\n --compressed\n\n If successful, the response body contains an instance of\n [`operation`](/workspace/cloud-search/docs/reference/rest/v1/operations#Operation). For\n example: \n\n {\n name: \"operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY\"\n }\n\n If unsuccessful, contact Cloud Search support.\n4. Use [operations.get](/workspace/cloud-search/docs/reference/rest/v1/operations/get) to verify that\n third-party support is initialized:\n\n curl \\\n 'https://cloudsearch.googleapis.com/v1/operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY?key=\n [YOUR_API_KEY]' \\\n --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \\\n --header 'Accept: application/json' \\\n --compressed\n\n When the third-party initialization is complete, it contains the\n field `done` set to `true`. For example: \n\n {\n name: \"operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY\"\n done: true\n }\n\nNext Steps\n----------\n\nHere are few next steps you might take:\n\n1. If you plan on using Google Cloud Search with a non-Google data repository,\n such as Microsoft® SharePoint®, you\n must create a data source. For instructions on\n adding a data source, refer to\n [Add a data source to search](https://support.google.com/a/answer/7056471).\n\n2. Once you set up your data source, you can\n [create and register schema](/workspace/cloud-search/docs/guides/schema-guide) to identify\n how Google Cloud Search should represent the data in the repository."]]