Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 谷歌数据API认证_Python_Django_Google Api_Gdata_Gdata Api - Fatal编程技术网

Python 谷歌数据API认证

Python 谷歌数据API认证,python,django,google-api,gdata,gdata-api,Python,Django,Google Api,Gdata,Gdata Api,我正在尝试让我的Django应用程序(不使用谷歌应用程序引擎)使用谷歌联系人数据API从谷歌联系人检索数据。经历 第一步(AuthSubRequest)是获取一次性使用令牌。下一步(AuthSubSessionToken),即将一次性令牌升级为会话令牌。python API调用UpgradeToSessionToken()对我来说根本不起作用,它给了我一个非授权异常: gd_client = gdata.contacts.service.ContactsService() gd_client.a

我正在尝试让我的Django应用程序(不使用谷歌应用程序引擎)使用谷歌联系人数据API从谷歌联系人检索数据。经历

第一步(AuthSubRequest)是获取一次性使用令牌。下一步(AuthSubSessionToken),即将一次性令牌升级为会话令牌。python API调用UpgradeToSessionToken()对我来说根本不起作用,它给了我一个非授权异常:

gd_client = gdata.contacts.service.ContactsService()
gd_client.auth_token = authsub_token
gd_client.UpgradeToSessionToken() 
作为替代方案,我希望通过“手动”构造HTTP请求使其工作:

url = 'https://www.google.com/accounts/AuthSubSessionToken'
headers = {
               'Content-Type': 'application/x-www-form-urlencoded',
               'Authorization': 'AuthSub token=' + authsub_token,
               'User-Agent': 'Python/2.6.1',
               'Host': 'https://www.google.com', 
               'Accept': 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2',
               'Connection': 'keep-alive',
           }
req = urllib2.Request(url, None, headers)
response = urllib2.urlopen(req)
这给了我一个不同的错误:

HTTP错误302:HTTP服务器返回一个重定向错误,该错误将导致无限循环。最后一条30倍的错误消息是:暂时移动


我做错了什么?我非常感谢您对我尝试使用的任何一种方法的帮助/建议:Python API调用(UpgradeToSessionToken)或使用urllib2手动构造HTTP请求。

根据2.0文档,有一个Python示例集

运行示例代码

Python客户端库发行版中的目录
samples/contacts/contacts\u example.py
下提供了一个完整的工作示例客户端,其中包含本文档中显示的所有示例代码

示例客户端对联系人执行多个操作,以演示联系人数据API的使用


希望它能为您指明正确的方向。

我最近也遇到过类似的问题。通过将“安全”设置为“真”,我的问题得到了解决


有四种不同的身份验证方法。使用AuthSub真的那么重要吗?如果你不能让AuthSub工作,那么就考虑这个方法。我很容易就把它用上了。

谢谢你的建议,我会试试看
  next = 'http://www.coolcalendarsite.com/welcome.pyc'
  scope = 'http://www.google.com/calendar/feeds/'
  secure = True
  session = True
  calendar_service = gdata.calendar.service.CalendarService()