通过代码登录到特定的Google云端硬盘帐户 [英] Login to a specific Google Drive account through code

查看:111
本文介绍了通过代码登录到特定的Google云端硬盘帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过代码从Android设备登录到Google帐户?

我问的原因是:

我想使用Google驱动器存储应用程序的内容,然后从该应用程序读取GDrive内容的文件夹结构并下载所需的内容.

I want to use google drive to store the contents for an app, and then from the app read the folder structure of the GDrive contents and download whatever is necessary.

我想在我的代码和登录名中为该特定帐户的用户名和密码进行硬编码.

I want to hardcode the username and password for that particular account in my code and login.

有可能吗?

我已经浏览了包括Google云端硬盘API在内的网络上的各种信息,但无法弄清楚如何登录到某个特定帐户.

I have gone through various things available on the web including the Google Drive APIs but have not been able to figure out how to login to some specific account.

我不是在寻找完整的解决方案,朝着正确的方向轻推就可以了!

I am not looking for a complete solution, a nudge in the right direction would be fine!

推荐答案

用户名/密码,也不支持基本授权.您需要完成OAuth 2.0流程. GoogleAccountCredential intent为您完成了许多工作.请参见 Android快速入门示例.

Username/password, aka basic authorization is not supported. You need to go through OAuth 2.0 flow. GoogleAccountCredential intent does much of the work for you. See the Android quickstart sample.

如果您不希望与用户互动,并希望为您的应用创建Google云端硬盘帐户来提供文件,则可以将加密的访问令牌和刷新令牌嵌入到您的应用中,并使用嵌入式令牌来创建凭据对象.在做出这样的决定之前,请先检查安全问题:

If you don't want user interaction and want to create a Google Drive account for your app to serve files, you may embed an encrypted access token and a refresh token into your application and init a credential object with the embedded tokens. Please review security concerns before taking such a decision:

Credential credential = new GoogleCredential.Builder()
    .setClientSecrets("...")
    ....
    .build();

credential.setAccessToken(storedAccessToken);
credential.setRefreshToken(storedRefreshToken)

这篇关于通过代码登录到特定的Google云端硬盘帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆