简体   繁体   English

谷歌驱动器/文档API点燃

[英]google drive/docs api in kindle fire

In my app my cloud services are provided by google drive (formely google docs) to interact with google docs I use this library: 在我的应用程序中,我的云服务是由Google驱动器(以前称为google docs)提供的,以便与我使用此库的google docs进行交互:

http://code.google.com/p/google-api-java-client/ http://code.google.com/p/google-api-java-client/

It works great but requires that the device has the Google Apis on it and a google account set up 它的运行效果很好,但要求设备上装有Google Apis并设置了Google帐户

Is there any other way to authenticate on google docs without using this library? 没有使用此库,还有其他方法可以在Google文档上进行身份验证吗? Or do I have to migrate my cloud provider to Dropbox? 还是我必须将云提供商迁移到Dropbox?

Thank you 谢谢

Your best bet is to use OAuth 2.0 using the Client-side flow which is designed (partly) for mobile devices. 最好的选择是使用OAuth 2.0,并使用(部分)为移动设备设计的客户端流程

Basically what you'll have to do is use a Web View and redirect your users to the OAuth 2.0 grant page and then after they have granted you access to their data you simply: 基本上,您要做的是使用Web视图并将用户重定向到OAuth 2.0授权页面,然后在他们授予您访问其数据的权限后,您只需:

  • Catch the auth code inside the web view 在网络视图内捕获身份验证代码
  • Close the web view 关闭网络视图
  • Exchange the auth code for a refresh and an access token 将身份验证代码交换为刷新和访问令牌
  • Keep the refresh token in your local database because it gives you unlimited access to the API => no need to trigger Auth flows any more. 将刷新令牌保留在本地数据库中,因为它使您可以无限制地访问API =>不再需要触发Auth流。

That's it! 而已! With the newly acquired OAuth 2.0 Access Token and Refresh Token you've got all you need to access the user's Drive data on their behalf and use the API. 借助新获得的OAuth 2.0访问令牌和刷新令牌,您将具有代表用户访问用户的云端硬盘数据并使用API​​所需的全部功能。 You've circumvented the Android Account Manager. 您已经绕过了Android客户经理。

There might even be some OAuth 2.0 / Web View client libraries available somewhere for Android, that would help a lot. 甚至可能有一些OAuth 2.0 / Web View客户端库可用于Android,这将大有帮助。

PS: this technique is widely used, for instance on iOS if you use the Facebook library, it will first check if there is the Facebook app installed. PS:此技术被广泛使用,例如在iOS上,如果您使用Facebook库,它将首先检查是否安装了Facebook应用程序。 If the Facebook app is not installed it will use OAuth 2 and the Web View technique automatically. 如果未安装Facebook应用程序,它将自动使用OAuth 2和Web View技术。 Google's Objective-C client library also uses that technique (as I've heard, never used it). Google的Objective-C客户端库也使用该技术(据我所知,从未使用过)。

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

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