# Introduction: Develop apps using the Data Portability API

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](https://support.google.com/accounts/answer/14452558).

## Prerequisites

Before releasing your app, it must be [approved](https://developers.google.com/data-portability/user-guide/client-verification) 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](https://support.google.com/accounts/answer/14452558) 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.

![The steps a developer follows to create an app using the Data Portability API](https://developers.google.com/static/data-portability/user-guide/images/dpapi-dev-flow.png)

1. Implement the OAuth consent flow for the user. In this example, the user is
   providing access to YouTube video data.

   1. The user clicks **Import YouTube Videos** and signs into their Google
      Account.

   2. 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`
   3. The user clicks **Next** on the OAuth consent screen, agrees to share
      their data, and provides account access.

   4. 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.

      **Note** : If the user wants to switch between *one-time access* and
      *time-based access* they will need to go through the consent flow again
      after the existing grant has been revoked. You can revoke the grant with
      `resetAuthorization()`, or the user can revoke on their [connections
      page](http://myaccount.google.com/connections).
   5. The user is redirected to the app.

   6. The developer obtains an OAuth token for the user.

2. 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.

   > [!TIP]
   > **Tip:** You should initiate the portability archive within 24 hours of user authorization.

3. 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.
4. Download the data archive using the signed URLs.

5. *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.

6. *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](https://developers.google.com/data-portability/user-guide/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.

![The steps a user takes to export their data](https://developers.google.com/static/data-portability/user-guide/images/dpapi-user-flow.png)

1. First, the user is presented with an option to retrieve their data.

2. Next, the user signs into their Google Account.

3. 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.

4. 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**.

5. 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.