Giới thiệu: Phát triển ứng dụng bằng Data Portability API (API Khả năng di chuyển dữ liệu)
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.
API Di chuyển dữ liệu cho phép bạn xây dựng các ứng dụng yêu cầu người dùng cấp quyền để di chuyển bản sao dữ liệu từ các dịch vụ của Google vào ứng dụng của bạn. Điều này cho phép di chuyển dữ liệu và tạo điều kiện chuyển đổi dịch vụ.
Trước khi phát hành, ứng dụng của bạn phải được Google phê duyệt.
Bạn cũng nên xác minh rằng người dùng ở vị trí của bạn có thể sử dụng Data Portability API. Để biết danh sách các quốc gia và khu vực được hỗ trợ, hãy xem phần Câu hỏi thường gặp trên trang "Chia sẻ bản sao dữ liệu của bạn với bên thứ ba".
Quy trình làm việc của nhà phát triển
Sau đây là các bước bạn cần làm để tạo một ứng dụng sử dụng API Di chuyển dữ liệu.
Triển khai quy trình xin phép OAuth cho người dùng. Trong ví dụ này, người dùng đang cấp quyền truy cập vào dữ liệu video trên YouTube.
Người dùng nhấp vào Nhập video trên YouTube rồi đăng nhập vào Tài khoản Google của họ.
Ứng dụng chuyển tiếp người dùng đến URL đồng ý OAuth. Xin lưu ý rằng URL mẫu này được đơn giản hoá và thiếu một số thông số:
Người dùng nhấp vào Tiếp theo trên màn hình yêu cầu đồng ý OAuth, đồng ý chia sẻ dữ liệu của họ và cấp quyền truy cập vào tài khoản.
Người dùng chọn dữ liệu cần chia sẻ và khoảng thời gian ứng dụng có thể truy cập vào dữ liệu đó (quyền truy cập một lần vào dữ liệu của họ hoặc quyền truy cập dựa trên thời gian trong 30 hoặc 180 ngày), sau đó nhấp vào Tiếp tục.
Lưu ý: Trong vòng tối đa 90 ngày trước khi mã thông báo OAuth của bạn hết hạn, người dùng có thể gia hạn quyền truy cập của bạn vào dữ liệu của họ trước khi mã thông báo OAuth của bạn hết hạn.
Nút gia hạn sẽ không xuất hiện nếu người dùng không có phạm vi sắp hết hạn trong vòng 90 ngày.
Lưu ý: Nếu muốn chuyển đổi giữa quyền truy cập một lần và truy cập dựa trên thời gian, người dùng sẽ cần phải thực hiện lại quy trình đồng ý sau khi quyền cấp hiện tại bị thu hồi. Bạn có thể thu hồi quyền cấp bằng resetAuthorization() hoặc người dùng có thể thu hồi trên trang kết nối của họ.
Người dùng được chuyển hướng đến ứng dụng.
Nhà phát triển sẽ lấy mã thông báo OAuth cho người dùng.
Ứng dụng của bạn gọi InitiatePortabilityArchive(resources = ["myactivity.youtube"]) bằng mã thông báo OAuth đính kèm có chứa phạm vi OAuth này:
Lệnh gọi này bắt đầu quá trình tạo bản lưu trữ dữ liệu và phản hồi bằng một mã công việc, cũng như liệu người dùng đã cấp quyền truy cập một lần hay quyền truy cập dựa trên thời gian.
Lưu ý: Quyền truy cập một lần có nghĩa là một lượt xuất cho mỗi phạm vi. Nếu người dùng cấp nhiều phạm vi, bạn có thể chọn tạo các công việc riêng biệt cho từng tài nguyên mà mã thông báo đã cho phép.
Ứng dụng của bạn gọi GetPortabilityArchiveState(job_id) bằng mã thông báo OAuth đính kèm chứa phạm vi OAuth này:
Bạn có thể gọi phương thức này nhiều lần để truy xuất trạng thái của công việc lưu trữ. Phương thức này trả về trạng thái của công việc. Nếu trạng thái là COMPLETE, thì bản lưu trữ đã sẵn sàng và các URL đã ký trên Cloud Storage sẽ được cung cấp. Xin lưu ý rằng thời gian hoàn tất yêu cầu lưu trữ có thể từ vài phút đến vài giờ, tuỳ thuộc vào kích thước dữ liệu.
Tải bản lưu trữ dữ liệu xuống bằng các URL đã ký.
Nếu người dùng cấp quyền truy cập một lần, bạn sẽ gọi ResetAuthorization() bằng mã thông báo OAuth đính kèm để đặt lại các tài nguyên đã dùng hết và xoá tất cả các lượt đồng ý OAuth.
Nếu người dùng cấp quyền truy cập dựa trên thời gian, bạn có thể xuất tài nguyên mỗi 24 giờ cho đến khi quyền đồng ý hết hạn.
Cách người dùng tương tác với ứng dụng Data Portability API
Sơ đồ này cho thấy cách người dùng tương tác với một ứng dụng được tích hợp với API Di chuyển dữ liệu.
Trước tiên, người dùng sẽ thấy một lựa chọn để truy xuất dữ liệu của họ.
Tiếp theo, người dùng đăng nhập vào Tài khoản Google của họ.
Sau đó, người dùng nhấp vào Tiếp theo khi được nhắc chia sẻ dữ liệu của họ, rồi nhấp vào Tôi hiểu khi được nhắc chấp nhận chính sách quyền riêng tư.
Sau đó, người dùng sẽ thấy màn hình yêu cầu đồng ý OAuth dùng để cho phép ứng dụng truy cập vào dữ liệu của họ. Các tuỳ chọn ở đây khớp với phạm vi OAuth mà bạn đã định cấu hình. Người dùng chọn dữ liệu cần chia sẻ và khoảng thời gian ứng dụng có thể truy cập vào dữ liệu đó (quyền truy cập một lần vào dữ liệu của họ hoặc quyền truy cập dựa trên thời gian trong 30 hoặc 180 ngày), sau đó nhấp vào Tiếp tục.
Sau khi bạn cho phép truy cập, quá trình nhập dữ liệu sẽ bắt đầu. Tuỳ thuộc vào kích thước của dữ liệu, yêu cầu này có thể mất từ vài phút đến vài giờ để hoàn tất.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003eThe Data Portability API allows developers to build applications that enable users to move a copy of their data from Google services to another application, facilitating service switching.\u003c/p\u003e\n"],["\u003cp\u003eBefore releasing an application using this API, developers must obtain approval from Google and ensure the API is available in the user's region.\u003c/p\u003e\n"],["\u003cp\u003eThe developer workflow involves implementing the OAuth consent flow, initiating the data archive creation, monitoring its status, downloading the archive using provided URLs, and finally resetting authorization.\u003c/p\u003e\n"],["\u003cp\u003eUsers interact with Data Portability API applications by initiating data retrieval, signing into their Google Account, granting necessary permissions, and waiting for the data import process to complete.\u003c/p\u003e\n"],["\u003cp\u003eData Portability API features are not accessible to users under 18 years of age, resulting in an error message if they attempt to use them.\u003c/p\u003e\n"]]],[],null,["# Introduction: Develop apps using the Data Portability API\n\nThe Data Portability API lets you build applications that request authorization from a\nuser to move a copy of data from Google services into your application. This\nenables data portability and facilitates switching services.\n\nIf you are looking for information on how users share data, see [Share a copy of\nyour data with a third party](https://support.google.com/accounts/answer/14452558).\n\nPrerequisites\n-------------\n\nBefore releasing your app, it must be [approved](/data-portability/user-guide/client-verification) by Google.\n\nYou should also verify that the Data Portability API is available to users in\nyour location. For a list of supported countries and regions, see\n[Common Questions](https://support.google.com/accounts/answer/14452558) on the \"Share a copy of your data with a third\nparty\" page.\n\nDeveloper workflow\n------------------\n\nThese are the steps you follow to create an application that uses the\nData Portability API.\n\n1. Implement the OAuth consent flow for the user. In this example, the user is\n providing access to YouTube video data.\n\n 1. The user clicks **Import YouTube Videos** and signs into their Google\n Account.\n\n 2. The app forwards the user to an OAuth consent URL. Note that this\n example URL is simplified and is missing some parameters:\n\n `https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/dataportability.myactivity.youtube`\n 3. The user clicks **Next** on the OAuth consent screen, agrees to share\n their data, and provides account access.\n\n 4. The user selects what data to share and the amount of time the app can\n access that data (*one-time access* to their data or *time-based access* for\n 30 or 180 days), then clicks **Continue**.\n\n **Note**:\n Up to 90 days before your OAuth token expires, the user has the option\n of renewing your access to their data before your OAuth token expires.\n The renew button doesn't appear if the user doesn't have scopes expiring\n within 90 days.\n\n **Note** : If the user wants to switch between *one-time access* and\n *time-based access* they will need to go through the consent flow again\n after the existing grant has been revoked. You can revoke the grant with\n `resetAuthorization()`, or the user can revoke on their [connections\n page](http://myaccount.google.com/connections).\n 5. The user is redirected to the app.\n\n 6. The developer obtains an OAuth token for the user.\n\n2. Your app calls\n `InitiatePortabilityArchive(resources = [\"myactivity.youtube\"])` with\n an attached OAuth token that contains this OAuth scope:\n\n `https://www.googleapis.com/auth/dataportability.myactivity.youtube`\n\n This call starts the process of creating the data archive and responds with\n a job ID and whether the user granted one-time or time-based access.\n\n **Note** :\n One-time access means one export *per scope*. If the user grants\n multiple scopes, you may choose to create separate jobs for each of the\n resources authorized by the token.\n | **Tip:** You should initiate the portability archive within 24 hours of user authorization.\n3. Your app calls `GetPortabilityArchiveState(job_id)` with an attached OAuth\n token that contains this OAuth scope:\n\n `https://www.googleapis.com/auth/dataportability.myactivity.youtube`\n\n You can call this method multiple times to retrieve the status of the\n archive job. The method returns the job's state. If the state is `COMPLETE`,\n the archive is ready, and signed Cloud Storage URLs are provided. Note that\n the time it takes to complete the archive request can vary from minutes to\n hours depending on the size of the data.\n4. Download the data archive using the signed URLs.\n\n5. *If the user grants one-time access* , you call `ResetAuthorization()` with\n an attached OAuth token to reset exhausted resources and to remove all OAuth\n consents.\n\n6. *If the user grants time-based access*, you can export resources every 24\n hours until the consent expires.\n\nFor more information on using the Data Portability API methods, see\n[Call Data Portability API methods](/data-portability/user-guide/methods).\n\nHow users interact with a Data Portability API app\n--------------------------------------------------\n\nThis diagram shows how users interact with an app that's integrated with the\nData Portability API.\n\n1. First, the user is presented with an option to retrieve their data.\n\n2. Next, the user signs into their Google Account.\n\n3. Then, the user clicks **Next** when they're prompted to share their data,\n and they click **I understand** when they're prompted to accept the privacy\n policy.\n\n4. Then, the user is shown an OAuth consent screen that is used to allow the\n application to access their data. The options here match the OAuth scopes\n you configured. The user selects what data to share and the amount of time\n the app can access that data (*one-time access* to their data or\n *time-based access* for 30 or 180 days), then clicks **Continue**.\n\n5. After allowing access, the data import starts. Depending on the size of the\n data, the request can take several minutes to several hours to complete."]]