Google Drive SDK和OAuth 2上的好教程? [英] Good tutorial on Google Drive SDK and OAuth 2?

查看:151
本文介绍了Google Drive SDK和OAuth 2上的好教程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够通过Google云端硬盘帐户读取网站上的文件,这让我拉我的头发,因为Google服务的文档太过分了(对我而言,无论如何,我几乎没有工作经验使用SDK和API)。我也意识到我需要使用OAuth 2授权来授予对文件的访问权限。任何好主意从哪里开始? 解决方案

您的第一步是决定是否要通过JavaScript访问云端硬盘客户端,或从Web服务器(PHP,Java等)。您的第二步是决定您是要使用抽象库还是直接编程到HTTP API。

这两种方法都有优点和缺点。就我个人而言,我选择使用低级HTTP API的原因如下: -


  1. 它们更稳定。这些库很容易发生突变,这可能会影响初学者。通常您会找到不能编译的示例代码v。当前库版本

  2. 我使用的第三方代码越少,维护起来越容易

  3. 我发现一些OAuth抽象有些奇怪,特别是在错误处理中。

  4. 如果您遇到错误,在SDK级别难以解决,您会发现无论如何,您自己需要追踪并理解底层的HTTP API。

  5. 许多库都标记为Beta,这会将它们排除在我公司的生产用途之外。

如果您选择使用HTTP API路由,那么您实际上只需要三种资源。





确保您将OAuth和云端硬盘视为单独的主题。先了解OAuth,然后解决Drive问题。



我确定有很多人使用libs成功了,所以我不会完全写下它们。由于上述原因,它们不适合我们。

还有一点,请记住OAuth关于授权,而不是认证。所以你仍然需要做你的认证和用户/会话管理。话虽如此,OAuth 不会将用户令牌作为副产品吐出,因此存在一些重叠。我的观点确实是你需要推出自己的用户/会话管理。


I want to be able to read in files on a website from a Google Drive account, which has made me pull my hair since the documentation for Google's services is so overwhelming (for me it is anyway, I have little experience with working with SDKs and APIs). I also realize that I need to use OAuth 2 authorization to grant access to the files. Any good ideas on where to start?

解决方案

Your first step is to decide whether you will be doing the Drive access from a Javascript client, or from a Web Server (php, Java, etc). OAuth is very different depending on which flow you will be using.

Your second step is to decide whether or not you want to use the abstraction libraries, or program directly to the HTTP API.

There are pros and cons to both methods. Personally I elected to use the low level HTTP APIs for the following reasons:-

  1. They are more stable. The libraries are prone to breaking changes which can frustrate beginners. Often you will find example code which won't compile v. the current library versions
  2. The less third party code I use, the easier it is for me to maintain
  3. I find some of the OAuth abstractions somewhat bizarre, especially in the error handling
  4. If you get errors, they can be difficult to resolve at the SDK level, and you find yourself needing to trace and hence understand the underlying HTTP API anyway.
  5. Many of the libraries are labelled Beta, which excludes them from production use in my company.

If you choose to go the HTTP API route, then there are really only three resources that you need.

Make sure you treat OAuth and Drive as separate topics. Understand OAuth first, then tackle Drive.

I'm sure a lot of people have success using the libs, so I won't write them off completely. They're just not for us for the reasons above.

One more tip, remember that OAuth is about Authorisation, not Authentication. So you still need to do your authentication and user/session management. Having said that, OAuth does spit out a user token as a by-product, so there is some overlap. My point is really that you need to roll your own user/session management.

这篇关于Google Drive SDK和OAuth 2上的好教程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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