简体   繁体   中英

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 .

Steps:-

  1. Create the Google Account (eg. 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/ )
  3. Create a new set of credentials (NB OAuth Client ID not Service Account Key and then choose "Web Application" from the selection)
  4. Include https://developers.google.com/oauthplayground as a valid redirect URI
  5. Note the client ID (web app) and Client Secret
  6. Login as my.drive.app@gmail.com
  7. Go to Oauth2 playground
  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
  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)
  10. Click Authorize APIs. You will be prompted to choose your Google account and confirm access
  11. Click Step 2 and "Exchange Authorization code for tokens"
  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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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