3

私はこの男と同じ状況にあります(私の問題は python にあるということだけです): サービス アカウントを使用してデータを取得しようとしています (この例を使用し、このブログ エントリを読んだ後、私のアプリケーションは Google アプリであるため)。ログインが必要なエラーが発生しましたが、その理由がわかりません。

全体の例でそれを表現しましょう:

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.">                   

なぜこれが起こっているのか、そしてそれを解決する方法についての指針は大歓迎です.

4

3 に答える 3

1

サービスアカウントはCalendarAPIで機能します。ドメイン管理へのアクセスも許可する必要があります。

user1260486とbtspierreが言ったように実行"prn=requestor@domain.com"し、のコンストラクターにを追加しSignedJWTAssertionCredentialsます。

次に、ドメイン管理に移動してclient_id、APIへのアクセスを追加します。

これがそれについてのウォークスルーです。スコープについては、"https://www.googleapis.com/auth/calendar, https://www.googleapis.com/auth/calendar.readonly"

于 2012-09-17T03:25:35.343 に答える
1

サービス アカウントが利用可能で、Calendar API for me と連携します。

次のステートメントを変更する必要があります。

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')
于 2012-05-20T07:28:21.630 に答える
0

Calendar API でサービス アカウントを使用できるとは思いません。サービス アカウントには独自のカレンダーはありません。

于 2012-05-14T23:10:18.517 に答える