The Data Portability API lets you build applications that request authorization from a user to move a copy of data from Google services into your application. This enables data portability and facilitates switching services.
If you are looking for information on how users share data, see Share a copy of your data with a third party.
Prerequisites
Before releasing your app, it must be approved by Google.
You should also verify that the Data Portability API is available to users in your location. For a list of supported countries and regions, see Common Questions on the "Share a copy of your data with a third party" page.
Developer workflow
These are the steps you follow to create an application that uses the Data Portability API.
Implement the OAuth consent flow for the user. In this example, the user is providing access to YouTube video data.
The user clicks Import YouTube Videos and signs into their Google Account.
The app forwards the user to an OAuth consent URL. Note that this example URL is simplified and is missing some parameters:
https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/dataportability.myactivity.youtube
The user clicks Next on the OAuth consent screen, agrees to share their data, and provides account access.
The user selects what data to share and the amount of time the app can access that data (one-time access to their data or time-based access for 30 or 180 days), then clicks Continue.
Note: Up to 90 days before your OAuth token expires, the user has the option of renewing your access to their data before your OAuth token expires. The renew button doesn't appear if the user doesn't have scopes expiring within 90 days.
The user is redirected to the app.
The developer obtains an OAuth token for the user.
Your app calls
InitiatePortabilityArchive(resources = ["myactivity.youtube"])
with an attached OAuth token that contains this OAuth scope:https://www.googleapis.com/auth/dataportability.myactivity.youtube
This call starts the process of creating the data archive and responds with a job ID and whether the user granted one-time or time-based access.
Note: One-time access means one export per scope. If the user grants multiple scopes, you may choose to create separate jobs for each of the resources authorized by the token.
Your app calls
GetPortabilityArchiveState(job_id)
with an attached OAuth token that contains this OAuth scope:https://www.googleapis.com/auth/dataportability.myactivity.youtube
You can call this method multiple times to retrieve the status of the archive job. The method returns the job's state. If the state is
COMPLETE
, the archive is ready, and signed Cloud Storage URLs are provided. Note that the time it takes to complete the archive request can vary from minutes to hours depending on the size of the data.Download the data archive using the signed URLs.
If the user grants one-time access, you call
ResetAuthorization()
with an attached OAuth token to reset exhausted resources and to remove all OAuth consents.If the user grants time-based access, you can export resources every 24 hours until the consent expires.
For more information on using the Data Portability API methods, see Call Data Portability API methods.
How users interact with a Data Portability API app
This diagram shows how users interact with an app that's integrated with the Data Portability API.
First, the user is presented with an option to retrieve their data.
Next, the user signs into their Google Account.
Then, the user clicks Next when they're prompted to share their data, and they click I understand when they're prompted to accept the privacy policy.
Then, the user is shown an OAuth consent screen that is used to allow the application to access their data. The options here match the OAuth scopes you configured. The user selects what data to share and the amount of time the app can access that data (one-time access to their data or time-based access for 30 or 180 days), then clicks Continue.
After allowing access, the data import starts. Depending on the size of the data, the request can take several minutes to several hours to complete.