我尝试在Python+Django和oauth2中使用googledocsapi。我通过googleapi python客户端获得了OAuth访问令牌等,代码基本上是从http://code.google.com/p/google-api-python-client/source/browse/samples/django_sample/plus/views.py复制的
现在,我想我应该使用googlegdataapi,v2.0.17。如果是这样,我就无法确切地找到如何授权使用gdata客户机进行的查询。位于http://packages.python.org/gdata/docs/auth.html#upgrading-to-an-access-token的文档(无论如何看起来都过时了),比如说将客户机上的auth\u token属性设置为gdata.oauth.OAuthToken. 如果是这样,我应该向OAuthToken传递什么参数?在
简而言之,我在寻找一个简单的示例,说明如何在给定OAuth访问令牌的情况下,授权使用gdataapi进行的查询。在
OAuth 2.0序列类似于以下内容(为已注册的应用程序提供适当定义的应用程序常量)。在
生成请求令牌。在
授权请求令牌。对于一个简单的命令行应用程序,您可以执行以下操作:
获取访问令牌。在
创建一个gdata客户端。在
授权客户。在
您可以保存访问令牌以备以后使用(因此避免在令牌再次过期之前必须执行手动身份验证步骤),方法是:
下次启动时,您可以通过执行以下操作来重用已保存的令牌:
然后,对身份验证序列的唯一更改是通过指定refresh_token参数将此令牌传递给OAuth2Token:
希望这有帮助。花了一段时间才弄明白:-)。在
这是来自https://developers.google.com/gdata/docs/auth/overview:
您应该同时使用OAuth进行授权和访问,或者使用OAuth 2.0进行授权和访问。在
对于OAuth 2.0,API现在位于https://developers.google.com/gdata/docs/directory。在
相关问题 更多 >
编程相关推荐