rocket
Giới thiệu
Merchant API – API chính thức thay thế cho Content API for Shopping.
add_alert
Lưu ý: Content API for Shopping sẽ ngừng hoạt động từ ngày 18 tháng 8 năm 2026.
Tài khoản dịch vụ
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.
Tài khoản dịch vụ là tài khoản Google đặc biệt mà các ứng dụng có thể sử dụng để truy cập vào các API của Google theo phương thức có lập trình thông qua OAuth 2.0. Tài khoản dịch vụ sử dụng quy trình OAuth 2.0 không yêu cầu sự cho phép của con người.
Thay vào đó, ứng dụng này sử dụng tệp khoá mà chỉ ứng dụng của bạn mới truy cập được. Hướng dẫn này thảo luận cách truy cập vào Content API for Shopping bằng tài khoản dịch vụ.
Lưu ý: Các ứng dụng dùng tài khoản dịch vụ để xác thực chỉ có thể truy cập vào tài khoản Merchant Center của riêng bạn. Nếu bạn đang viết một ứng dụng của bên thứ ba cần quyền truy cập vào tài khoản Merchant Center của khách hàng, vui lòng xem hướng dẫn về Yêu cầu uỷ quyền.
Điều kiện tiên quyết
Các bước sử dụng tài khoản dịch vụ để truy cập Content API for Shopping
- Tạo thông tin xác thực tài khoản dịch vụ hoặc truy cập thông tin xác thực công khai mà bạn đã tạo. Bạn sẽ cần tạo mã ứng dụng khách OAuth 2.0 và lấy tệp khoá riêng tư *.json:
- Chuyển đến Google API Console.
- Chọn một dự án trong trình đơn thả xuống ở đầu trang. Nếu bạn chưa có dự án, hãy tạo dự án bằng cách nhấp vào DỰ ÁN MỚI.
- Nếu bạn chưa bật Content API for Shopping cho dự án này, hãy tìm dự án này trong danh sách API của Google rồi bật.
- Trong thanh bên ở bên trái, hãy chọn Thông tin xác thực.
Bạn có thể phải nhấp vào mũi tên chỉ sang trái ở trên cùng bên trái để xem.
- Để thiết lập tài khoản dịch vụ, hãy chọn TẠO THÔNG TIN XÁC THỰC, sau đó chọn Tài khoản dịch vụ.
- Đặt tên cho tài khoản dịch vụ mới. Tên này cũng đóng vai trò là tên người dùng mặc định cho mã tài khoản dịch vụ. Ghi lại mã tài khoản dịch vụ, bao gồm cả phần sau ký tự "@" để sử dụng sau này. Nhấp vào TẠO, sau đó thực hiện các bước không bắt buộc để cấp quyền truy cập vào dự án và người dùng, rồi nhấp vào XONG.
Lựa chọn vai trò cho tài khoản dịch vụ sẽ không ảnh hưởng đến những lệnh gọi có thể thực hiện đến Content API, vì quyền truy cập vào các phương thức Content API được xác định thay thế theo vai trò liên kết với mã tài khoản dịch vụ trong Merchant Center. Nếu bạn không chắc nên chọn mục nào, hãy chọn Project > Viewer (Dự án > Trình xem).
- Bạn sẽ được chuyển hướng đến trang Tài khoản dịch vụ để truy cập vào tài khoản dịch vụ mới.
- Để lấy khoá riêng tư JSON, hãy nhấp vào tài khoản dịch vụ, sau đó nhấp vào thẻ KHOÁ. Nhấp vào THÊM KHOÁ > Tạo khoá mới, rồi chọn JSON làm loại khoá. Nhấp vào CREATE (TẠO) để tải khoá riêng tư xuống máy tính.
- Thêm tài khoản dịch vụ mới làm người dùng vào tài khoản Merchant Center. Nếu là nhà phát triển bên thứ ba, bạn sẽ cần khách hàng thực hiện bước này cho mình.
- Truy cập vào tài khoản Merchant Center.
- Chuyển đến phần Quyền truy cập vào tài khoản trong phần cài đặt của tài khoản Merchant Center.
- Nhấp vào + Thêm người dùng rồi sử dụng mã tài khoản dịch vụ làm địa chỉ email cho người dùng mới.
Nếu bạn chưa ghi lại mã tài khoản dịch vụ trước đó, hãy chuyển đến trang quản trị Service Accounts (Tài khoản dịch vụ) rồi chọn dự án bạn đã tạo.
- Chỉ định các lựa chọn ưu tiên Quyền truy cập của người dùng và Thông báo qua email cho tài khoản dịch vụ. Xin lưu ý rằng để sử dụng dịch vụ
Accounts
, bạn cần có quyền Quản trị.
- Nhấp vào Thêm người dùng để lưu lựa chọn ưu tiên và quay lại danh sách người dùng. Mã tài khoản dịch vụ phải được liệt kê cùng với vai trò người dùng đã chọn.
- Lặp lại quy trình này cho tất cả các tài khoản dịch vụ khác mà bạn muốn thêm.
- Giờ đây, bạn có thể truy cập vào tài khoản Merchant Center bằng tài khoản dịch vụ thông qua quy trình Thông tin xác thực mặc định của ứng dụng Google hoặc trực tiếp sử dụng quy trình tài khoản dịch vụ. Mẫu Content API for Shopping cho biết cách sử dụng cả hai luồng cho thông tin xác thực tài khoản dịch vụ trong từng ngôn ngữ lập trình được hỗ trợ.
Vui lòng xem các mã mẫu để dùng thử tài khoản dịch vụ mới và tìm hiểu những thay đổi cần thiết để sử dụng tài khoản dịch vụ trong mã của riêng bạn.
Câu hỏi thường gặp
- Tôi có thể đăng nhập vào giao diện người dùng Merchant Center bằng tài khoản dịch vụ của mình không?
- Không, tài khoản dịch vụ không phải là Tài khoản Google thông thường và không thể truy cập vào giao diện người dùng Merchant Center.
- Tôi cần làm mới mã truy cập tài khoản dịch vụ bao lâu một lần?
- Mã truy cập sẽ hết hạn một giờ sau khi được Máy chủ uỷ quyền OAuth 2.0 của Google cấp. Khi mã truy cập hết hạn, ứng dụng sẽ dùng thư viện ứng dụng để tìm nạp một mã truy cập khác.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[[["\u003cp\u003eService accounts enable applications to programmatically access Google APIs, including the Content API for Shopping, using OAuth 2.0 without human intervention.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize service accounts, you need to generate service account credentials, add the service account as a user in your Merchant Center account, and then access your Merchant Center account using either the Google Application Default Credentials flow or the service account flow.\u003c/p\u003e\n"],["\u003cp\u003eApplications authenticated with service accounts can only access your own Merchant Center account; for third-party applications needing access to client accounts, refer to the Authorizing Requests guide.\u003c/p\u003e\n"],["\u003cp\u003eService accounts cannot be used to sign in to the Merchant Center UI and access tokens expire after one hour, requiring the application to fetch a new one using the client library.\u003c/p\u003e\n"]]],["Service accounts allow applications to access the Content API for Shopping programmatically. Key actions include: generating service account credentials by creating an OAuth 2.0 Client ID and a JSON private key file via the Google API Console, and adding the service account as a user within the Merchant Center account, specifying access and notification preferences. To access the Merchant center, you can use Google Application Default Credentials or a service account flow, with example code available. Access tokens expire hourly, requiring renewal.\n"],null,["# Service accounts are special Google accounts that can be used by\napplications to access Google APIs programmatically via OAuth 2.0. A service\naccount uses an OAuth 2.0 flow that does not require human authorization.\nInstead, it uses a key file that only your application can access. This guide\ndiscusses how to access the Content API for Shopping with service accounts.\n\n**Note:** Applications using service accounts\nfor authentication can only access your own Merchant Center account. If you are\nwriting a third-party application that needs access to your clients' Merchant\nCenter accounts, please see the [Authorizing Requests](/shopping-content/guides/how-tos/authorizing)\nguide instead.\n\nPrerequisites\n-------------\n\n- A [Merchant Center](//merchants.google.com/) account.\n\nSteps to using a service account to access the Content API for Shopping\n-----------------------------------------------------------------------\n\n1. Generate service account credentials or access the public credentials you've already generated. You will need to create an OAuth 2.0 Client ID and obtain a \\*.json private key file:\n 1. Go to the [Google API Console](https://console.cloud.google.com/apis/library).\n 2. Select a project in the drop-down menu at the top of the page. If you do not have one yet, create one by clicking **NEW PROJECT**.\n 3. If you have not already enabled the Content API for Shopping for this project, then search for it in the list of Google APIs and enable it.\n 4. In the sidebar on the left, select **Credentials**. You may need to click the left-pointing arrow at the top left to see this.\n 5. To set up a service account, select **CREATE CREDENTIALS** , and then **Service account** . \n 6. Name the new service account. This also serves as the default username for the service account ID. Record the service account ID, including the part after the '@' character, for later use. Click **CREATE** , then go through the optional steps of granting access to project and users, and click **DONE** .\n\n The choice of role for the service account will not\n have any effect on what calls can be made to the Content API, as access to\n Content API methods is determined instead by the role associated with the\n service account ID in Merchant Center. If you are unsure what to pick, just\n pick **Project \\\u003e Viewer**.\n 7. You will be directed to the Service Accounts page where your new service account can be accessed.\n 8. To obtain a JSON private key, click on the service account, then the **KEYS** tab. Click **ADD KEY \\\u003e Create new key** and then select JSON as the key type. Click **CREATE** to download the private key to your computer.\n2. Add the new service account as a user to your Merchant Center account. If you are a third-party developer, you will need to have your client do this step for you.\n 1. Go to your [Merchant\n Center account](//merchants.google.com/).\n 2. Go to **Account Access** in the settings of your Merchant Center account.\n 3. Click **+ Add user** and use the service account ID as the email address for the new user.\n\n If you did not take note of the\n service account ID earlier, go to the [Service\n Accounts](//console.developers.google.com/iam-admin/serviceaccounts/) administration page and select the project you created.\n 4. Specify the **User access** and **Email notifications** preferences for the service account. Note that the use of the `Accounts` service requires **Admin** access.\n 5. Click **Add user** to save preferences and be returned to the list of users. The service account ID should be listed with the chosen user role.\n 6. Repeat the process for all other service accounts you want to add.\n3. Now you can access your Merchant Center account using the service account either by using the [Google Application\n Default Credentials](/identity/protocols/application-default-credentials) flow or by using the [service account flow](/identity/protocols/OAuth2ServiceAccount) directly. The Content API for Shopping [Samples](/shopping-content/guides/libraries) show how to use both flows for service account credentials in each supported programming language. Please check out the code samples to try out your new service account and to learn what changes you will need to use service accounts in your own code.\n\nFrequently asked questions\n--------------------------\n\nCan I sign in to the Merchant Center UI with my service account?\n: No, service accounts are not regular Google accounts and cannot access the\n Merchant Center UI.\n\nHow often do I need to refresh service account access tokens?\n: Access tokens expire one hour after they are issued by the Google OAuth 2.0\n Authorization Server. When an access token expires, the application should use\n the client library to fetch another access token."]]