简体   繁体   English

通过代码登录到特定的Google云端硬盘帐户

[英]Login to a specific Google Drive account through code

Is it possible to login into a google account from an android device through code? 是否可以通过代码从Android设备登录到Google帐户?

The reason i'm asking is this: 我问的原因是这样的:

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. 我想使用Google Drive来存储应用程序的内容,然后从该应用程序读取GDrive内容的文件夹结构并下载所需的内容。

I want to hardcode the username and password for that particular account in my code and login. 我想在代码和登录名中硬编码该特定帐户的用户名和密码。

Is it possible? 可能吗?

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. 我已经浏览了包括Google云端硬盘API在内的网络上的各种信息,但是还无法弄清楚如何登录到某个特定帐户。

I am not looking for a complete solution, a nudge in the right direction would be fine! 我不是在寻找完整的解决方案,朝正确的方向轻推就可以了!

Username/password, aka basic authorization is not supported. 不支持用户名/密码,即基本授权。 You need to go through OAuth 2.0 flow. 您需要完成OAuth 2.0流程。 GoogleAccountCredential intent does much of the work for you. GoogleAccountCredential意图为您完成了许多工作。 See the Android quickstart sample . 请参阅Android快速入门示例

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. 如果您不希望与用户互动,并希望为您的应用创建Google云端硬盘帐户来提供文件,则可以将加密的访问令牌和刷新令牌嵌入到您的应用中,并使用嵌入式令牌来初始化凭据对象。 Please review security concerns before taking such a decision: 在做出此类决定之前,请先检查安全问题:

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

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

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

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