【问题标题】:Unauthorized interaction with google calendar API v3与谷歌日历 API v3 的未经授权的交互
【发布时间】:2012-05-22 10:33:58
【问题描述】:

我的情况与this guy 相同(只是我的问题在于python):我正在尝试使用服务帐户检索数据(使用this example 并在阅读this blog entry 之后因为我的应用程序是谷歌应用程序),但我遇到了需要登录错误,我不明白为什么。

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

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(                            
        '2127313127654990@developer.gserviceaccount.com', 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.">                   

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

【问题讨论】:

  • 也许您不应该包含所有凭据,毕竟这是一个面向公众的网站...
  • 都是假的,别担心。感谢您的关心。

标签: python google-api oauth-2.0 google-calendar-api google-api-python-client


【解决方案1】:

服务帐户可供我使用并与日历 API 一起使用。

您需要更改以下语句:

credentials = SignedJwtAssertionCredentials('2127313127654990@developer.gserviceaccount.com', key, scope=['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly'])

credentials = SignedJwtAssertionCredentials('2127313127654990@developer.gserviceaccount.com', key, scope=['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly'], prn='requestor@domain.com')

【讨论】:

  • 嗨,我正在尝试做同样的事情。如果日历所有者的电子邮件地址是“john.doe@gmail.com”,那是我要在“prn”字段中输入的吗?您知道日历是否必须以任何方式进行配置(例如公开)?我不断收到“访问被拒绝”错误,上面写着“刷新 OAuth2 令牌时出错”(我正在使用 PHP 库)。我的日历设置为公开。谢谢。
【解决方案2】:

服务帐户确实可以与日历 API 一起使用。您还必须授予对域管理的访问权限。

按照user1260486和btspierre所说的,将"prn=requestor@domain.com"添加到SignedJWTAssertionCredentials的构造函数中。

然后转到您的域管理并添加您对 API 的client_id 访问权限。

这是一个关于它的walkthrough。 对于范围指定"https://www.googleapis.com/auth/calendar, https://www.googleapis.com/auth/calendar.readonly"

【讨论】:

    【解决方案3】:

    我认为日历 API 不能使用服务帐户。服务帐号没有自己的日历。

    【讨论】:

    • 这可以解释。让我在问题跟踪器中提问
    • 我之前已经成功让它工作了。 Schillingt 已经证明这个答案是错误的。
    • 这是旧信息。服务帐户确实可用于 Calendar API(至少使用 v3 测试过)。
    猜你喜欢
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 2012-02-13
    相关资源
    最近更新 更多