与 Google 日历 API v3 进行未经授权的交互

2024-01-11

我的情况与this guy https://stackoverflow.com/questions/10112939/login-required-401-unauthorized-message-when-calling-the-v3-google-calendar-ap(只是我的问题与Python有关):我正在尝试使用服务帐户检索数据(使用这个例子 http://code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py阅读后这个博客条目 http://googleappsdeveloper.blogspot.com.ar/2011/12/calendar-api-v3-2-legged-oauth-java.html因为我的应用程序是谷歌应用程序)但我遇到了要求登录错误,我不明白为什么。

让我用一个完整的例子来表示它:

In [1]: import httplib2                                                          
In [2]: from apiclient.discovery import build                                   
In [3]: from oauth2client.client import SignedJwtAssertionCredentials            
In [4]: f = open('abd45679ffg32343-privatekey.p12', 'rb')
In [5]: key = f.read()                                                          
In [6]: f.close()                                                               
In [7]: credentials = SignedJwtAssertionCredentials(                            
        '[email protected] /cdn-cgi/l/email-protection', key,                     
        scope=['https://www.googleapis.com/auth/calendar',                      
               'https://www.googleapis.com/auth/calendar.readonly'])            
In [8]: http = httplib2.Http()                                                  
In [9]: http = credentials.authorize(http)                                      
In [10]: service = build(serviceName='calendar', version='v3', http=http,       
   ....:         developerKey='XcddfRgtyt676grggtT')        
2012-05-14 18:24:35,170 INFO  [root][MainThread] URL being requested: https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest                                                              
2012-05-14 18:24:35,170 INFO  [oauth2client.client][MainThread] Attempting refresh to obtain initial access_token
2012-05-14 18:24:35,179 INFO  [oauth2client.client][MainThread] Refresing access_token
In [11]: service.calendarList().list().execute()                                
2012-05-14 18:25:00,418 INFO  [root][MainThread] URL being requested https://www.googleapis.com/calendar/v3/users/me/calendarList?alt=json&key=XcddfRgtyt676grggtT          
---------------------------------------------------------------------------     
HttpError                                 Traceback (most recent call last)     
/home/mariano/Code/Kalendar/rest/kalendar/<ipython-input-12-0cb769615d74> in <module>()
----> 1 service.calendarList().list().execute()                                 
/home/mariano/Code/Kalendar/rest/env/local/lib/python2.7/site-packages/google_api_python_client-1.0beta8-py2.7.egg/apiclient/http.pyc in execute(self, http)                                     
387                                                                         
388       if resp.status >= 300:                                            
--> 389         raise HttpError(resp, content, self.uri)                        
390     return self.postproc(resp, content)                                 
391                                                                         
HttpError: <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/users/me/calendarList?alt=json&key=XcddfRgtyt676grggtT returned "The user must be signed up for Google Calendar.">                   

任何关于为什么会发生这种情况以及如何解决它的指示将不胜感激。


服务帐户可用,并且可以与我的日历 API 一起使用。

您需要更改以下声明:

credentials = SignedJwtAssertionCredentials('[email protected] /cdn-cgi/l/email-protection', key, scope=['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly'])

to

credentials = SignedJwtAssertionCredentials('[email protected] /cdn-cgi/l/email-protection', key, scope=['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly'], prn='[email protected] /cdn-cgi/l/email-protection')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

与 Google 日历 API v3 进行未经授权的交互 的相关文章

随机推荐