简体   繁体   English

获取OAuth2凭据,以便在具有Google云端硬盘应用拥有的帐户的Android应用中使用

[英]Getting OAuth2 credentials for use in an Android application with a Google Drive application-owned account

I'm developing an Android application where the user has requested to use Google Drive as a bootstrap CMS while they develop a real CMS for the second version of the app. 我正在开发一个Android应用程序,其中用户已请求使用Google云端硬盘作为引导CMS,而他们为该应用程序的第二版开发了一个真正的CMS。 This means they will want to access the Drive console and edit documents in it, and our app will then need to retrieve these. 这意味着他们将要访问云端硬盘控制台并在其中编辑文档,然后我们的应用将需要检索这些内容。

I've determined that the best way to do this is using a regular Drive account that is application-owned, as described here: 我确定最好的方法是使用应用程序拥有的常规云端硬盘帐户,如下所述:

Use regular Google accounts as application-owned accounts 将常规Google帐户用作应用程序拥有的帐户

This requires us to get OAuth2 credentials for the user. 这要求我们获取用户的OAuth2凭据。 The article linked above links to a secondary article about doing that: 上面链接的文章链接到有关此操作的第二篇文章:

Retrieve and Use OAuth 2.0 Credentials 检索和使用OAuth 2.0凭据

In it, they show a program for retrieving OAuth2 credentials using an authorization code . 在其中,它们显示了一个使用授权代码检索OAuth2凭据的程序 According to the drive documentation, it is sufficient to do this once. 根据驱动器文档,只需执行一次即可。

How do I get the authorization code given the login/pass combination, and is that really the simplest way to get the OAuth2 credentials once I have? 给定登录名/密码组合,如何获得授权码?这是获得OAuth2凭证后最简单的方法吗?

Moreover, what does the state parameter do and how do you set it? 此外,状态参数有什么作用,如何设置?

You can get the auth token by following the steps here: 您可以按照以下步骤获取auth令牌:

Using OAuth 2.0 for Web Server Applications 将OAuth 2.0用于Web服务器应用程序

The state parameter is described here: 状态参数在这里描述:

google oauth2 redirect_uri with several parameters 带有多个参数的Google oauth2 redirect_uri

and is an encoded string that allows the redirect URL to pass back state to the web app being used to get the OAuth2 token. 并且是一个编码的字符串,该字符串允许重定向URL将状态传递回用于获取OAuth2令牌的网络应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM