简体   繁体   English

Android应用中的Google Drive Api身份验证

[英]Google Drive Api authentication in Android app

我在Android应用程序中使用Google驱动器,我的应用程序会拍摄照片并上传以自动驱动,但是身份验证问题是我打开应用程序时第一次要求选择Google帐户,我可以以编程方式提供我的凭据并完成身份验证吗这样我就可以避免使用UI进行选择和身份验证的步骤。

You may refer with this link . 您可以参考此链接 This can be done with the Oauth2 Playground at https://developers.google.com/oauthplayground . 可以通过位于https://developers.google.com/oauthplayground的Oauth2游乐场来完成。

Steps:- 脚步:-

  1. Create the Google Account (eg. my.drive.app@gmail.com) 创建Google帐户(例如my.drive.app@gmail.com)
  2. Use the API console to register the mydriveapp ( https://console.developers.google.com/apis/credentials/oauthclient?project=mydriveapp or just https://console.developers.google.com/apis/ ) 使用API​​控制台注册mydriveapp( https://console.developers.google.com/apis/credentials/oauthclient?project=mydriveapp或仅https://console.developers.google.com/apis/
  3. Create a new set of credentials (NB OAuth Client ID not Service Account Key and then choose "Web Application" from the selection) 创建一组新的凭据(NB OAuth Client ID 不是 Service Account Key ,然后从选择中选择“ Web应用程序”)
  4. Include https://developers.google.com/oauthplayground as a valid redirect URI 包括https://developers.google.com/oauthplayground作为有效的重定向URI
  5. Note the client ID (web app) and Client Secret 注意客户端ID(Web应用程序)和客户端密钥
  6. Login as my.drive.app@gmail.com 以my.drive.app@gmail.com身份登录
  7. Go to Oauth2 playground 前往Oauth2游乐场
  8. In Settings (gear icon), set * Oauth flow: server * Access type: offline * Use your own OAuth credentials: TICK * Client Id and Client Secret: from step 5 在“设置”(齿轮图标)中,设置* Oauth流:服务器*访问类型:脱机*使用您自己的OAuth凭据:TICK *客户端ID和客户端密钥:从步骤5开始
  9. Click Step 1 and choose Drive API https://www.googleapis.com/auth/drive (having said that, this technique also works for any of the Google APIs listed) 点击第1步,然后选择Drive API https://www.googleapis.com/auth/drive (尽管如此,该技术也适用于所列的任何Google API)
  10. Click Authorize APIs. 单击授权API。 You will be prompted to choose your Google account and confirm access 系统将提示您选择您的Google帐户并确认访问权限
  11. Click Step 2 and "Exchange Authorization code for tokens" 单击步骤2和“令牌的Exchange授权代码”
  12. Copy the returned Refresh Token and paste it into your app, source code or in to some form of storage from where your app can retrieve it. 复制返回的刷新令牌,并将其粘贴到您的应用程序,源代码中或粘贴到某种形式的存储中,您的应用程序可以从中获取它。

You may also use Service Account . 您也可以使用“ 服务帐户” However, it would create a pseudo Drive account for the app, rather than allow the app to access your regular Drive account. 但是,它将为该应用程序创建一个伪云端硬盘帐户,而不是允许该应用程序访问您的常规云端硬盘帐户。 Check this . 检查一下

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

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