请求 Data Portability API 范围(例如 https://www.googleapis.com/auth/dataportability.*)时,不能与其他范围(例如 https://www.googleapis.com/auth/userinfo.email)混合使用。以下是一个无效请求示例,其中受限部分已加粗体:
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eTo use the Data Portability API, set up an OAuth workflow for your application using Google Identity documentation guidance for web, JavaScript, or mobile/desktop apps.\u003c/p\u003e\n"],["\u003cp\u003eEnable specific Data Portability API OAuth scopes for the desired data access, noting some scopes have restrictions and require additional handling for partial user consent.\u003c/p\u003e\n"],["\u003cp\u003eUser consent allows one data export; new consent is needed for subsequent downloads, and applications cannot directly identify the consenting Google Account due to token opacity.\u003c/p\u003e\n"],["\u003cp\u003eWhen requesting Data Portability API scopes, avoid mixing them with other scopes and refrain from using \u003ccode\u003einclude_granted_scopes=true\u003c/code\u003e to prevent errors.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the schema reference page or the Restricted Scopes page for a comprehensive list of all OAuth scopes and their categories within the Data Portability API.\u003c/p\u003e\n"]]],[],null,["To configure OAuth for your application, you set up an OAuth workflow, and you\nenable the Data Portability API OAuth scopes.\n\nSet up an OAuth workflow\n\nTo set up an OAuth flow for your application, follow the [basic steps](https://developers.google.com/identity/protocols/oauth2#basicsteps) in\nthe Google Identity documentation.\n\nMost developers use the [Server-side Web Apps](https://developers.google.com/identity/protocols/oauth2/web-server) flow for obtaining OAuth\nconsent, but you can also use the [JavaScript Web Apps flow](https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow) or the\n[Mobile and Desktop Apps flow](https://developers.google.com/identity/protocols/oauth2/native-app).\n\nExports can take longer than the lifetime of an access token, or the user could\ngrant 30 or 180 days of access. You may need to obtain a refresh token and\nperiodically exchange it for a fresh access token. For more details, see\n[Refreshing an access token for Web Apps](https://developers.google.com/identity/protocols/oauth2/web-server#offline) and\n[Refreshing an access token for Mobile and Desktop Apps](https://developers.google.com/identity/protocols/oauth2/native-app#offline).\n\n**Important** : OAuth token renewal is only available to users if your OAuth\nclient has a publishing status of **In production** , not **Testing** .\nAdditionally, tokens granted to OAuth clients with a **Testing** publishing\nstatus *always expire in 7 days* even if you select a 30- or 180-day duration.\nFor details, see [Setting up your OAuth consent screen](https://support.google.com/cloud/answer/10311615?sjid=1423889632047624286-NC#zippy=%2Cin-production).\n\nData Portability API OAuth scopes\n\nWhen you configure your Data Portability API application for OAuth, enable the\nData Portability API OAuth scopes that are relevant to your application. Some scopes\nare `sensitive` and `restricted` and are subject to additional requirements.\n\nWhen you add the Data Portability API scopes to your OAuth flow, there may be cases\nwhere your user gives consent to some but not all of the scopes. Your app must\nbe able to handle these cases by:\n\n- Allowing partial data exports\n- Notifying the user that they didn't select all the necessary scopes (and failing gracefully)\n- Asking the user for the remaining consents\n\nAdditionally, a user chooses whether to grant you access to their data once, or\nfor 30 or 180 days.\n\n- If a user grants you one-time access, your app is allowed to perform **one** data export for that specific consent. To download the data again, you need a new consent from the user.\n- If a user grants you time-based access, your app is allowed to perform data exports for the duration of specified time period or until the user revokes consent.\n- You can also choose to apply [time filters](/data-portability/user-guide/time-filter) to your request to export data for a specific range of time, such as the last 6 months.\n\nYou should also note that during the OAuth flow, your app does not know which\nGoogle Account was used to give consent. The OAuth token your application\nreceives is opaque.\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\nScopes restrictions\n\nThis section covers restrictions in scopes that result in errors.\n\nMixed scopes\n\nRequests for Data Portability API scopes (such as,\nhttps://www.googleapis.com/auth/dataportability.\\*) can't be mixed with other\nscopes (such as, https://www.googleapis.com/auth/userinfo.email). Here is an\nexample of a bad request, with the restricted part bolded: \n\n https://accounts.google.com/o/oauth2/v2/auth?\n client_id=\u003cvar translate=\"no\"\u003eclient_id\u003c/var\u003e&\n redirect_uri=\u003cvar translate=\"no\"\u003eredirect_uri\u003c/var\u003e&\n response_type=token&\n scope=https://www.googleapis.com/auth/dataportability.myactivity.search+https://www.googleapis.com/auth/userinfo.email&\n include_granted_scopes=false\n\nPreviously granted scopes\n\nYou should never set `include_granted_scopes=true` when requesting DPAPI scopes.\nHere is an example of a bad request, with the restricted part bolded: \n\n https://accounts.google.com/o/oauth2/v2/auth?\n client_id=\u003cvar translate=\"no\"\u003eclient_id\u003c/var\u003e&\n redirect_uri=\u003cvar translate=\"no\"\u003eredirect_uri\u003c/var\u003e&\n response_type=token&\n scope=https://www.googleapis.com/auth/dataportability.myactivity.search&\n include_granted_scopes=true\n\nToo many scopes\n\nIf your request has too many scopes appended, you may encounter a\n`400 bad request` error. This occurs when the URL length grows beyond what is\nsupported in browsers. To resolve, split your requests for scopes into multiple\nsmaller batches and use [Incremental authorization](https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow#incrementalAuth) to request\nconsent for each batch.\n| **Tip:** The length of the request is variable based on the length of the scopes. If the request fails, reduce the number of scopes and try again.\n\nScopes categories\n\nFor list of all OAuth scopes supported by the Data Portability API and their\ncategories, see [Available OAuth scopes](/data-portability/user-guide/scopes). For a list of all resource\ngroups and OAuth scopes supported by a particular service, see the [schema\nreference page](/data-portability/schema-reference) for that service.\n| **Tip:** If you want to view only the `restricted` scopes, see the Google Cloud Consoles's [Restricted Scopes page](https://support.google.com/cloud/answer/13464325#zippy=%2Cdata-portability-api)."]]