

# 为 Google Sheets 设置授权码 OAuth 流
<a name="googlesheets-oauth-authorization"></a>

 **先决条件** 
+  您可以在登录后使用 Google Sheets 应用程序的 Google 账户。在您的 Google 账户中，Google Sheets 已包含要传输的数据。
+  一个 Google Cloud Platform 账户和 Google Cloud 项目。有关更多详细信息，请参阅 [Create Google Cloud Project](https://developers.google.com/workspace/guides/create-project)。

**要设置 Google 账户并获取 OAuth 2.0 凭证，请按以下步骤操作：**

1.  设置好 Google Cloud 项目后，在该项目中启用 Google Sheets API 和 Google Drive API。有关启用步骤，请参阅 Google Cloud Platform 的 API Console 帮助中的 [Enable and disable APIs](https://support.google.com/googleapi/answer/6158841)。

1.  然后为外部用户配置 OAuth 同意屏幕。有关 OAuth 同意屏幕的更多信息，请参阅 Google Cloud Platform Console 帮助中心中的 [Setting up your OAuth consent screen](https://support.google.com/cloud/answer/10311615#)。

1.  在 OAuth 同意屏幕中，添加以下范围：
   +  [Google Sheets API 只读范围](https://www.googleapis.com/auth/spreadsheets.readonly) 
   +  [Google Drive API 只读范围](ttps://www.googleapis.com/auth/drive.readonly) 

    有关这些范围的更多信息，请参阅 Google Identity 文档中的 [OAuth 2.0 Scopes for Google APIs](https://developers.google.com/identity/protocols/oauth2/scopes)。

1.  生成 OAuth 2.0 客户端 ID 和密钥。有关创建此客户端 ID 的步骤，请参阅 Google Cloud Platform Console 帮助中的 [Setting up OAuth 2.0](https://support.google.com/cloud/answer/6158849?hl=en#zippy=)。

    OAuth 2.0 客户端 ID 必须有一个或多个经过授权的重定向 URL。

    重定向 URL 采用以下格式：
   + https://<aws-region>.console.aws.amazon.com/gluestudio/oauth 

1.  记下 OAuth 2.0 客户端 ID 设置中的客户端 ID 和客户端密钥。