0

사소한 일이되어야하지만 해결할 수는 없습니다.Google API python 클라이언트에 대한 App Engine 호출은 @oauth_required와 함께 403을 반환합니다.

Gae에서 Google 캘린더 API를 호출해야합니다. 따라서 나는 구글 문서 도구 및 예에 따라 모든 설정 : main.py 기능에 의해 호출

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json') 
SCOPES = [ 
    'https://www.googleapis.com/auth/calendar', 
] 
decorator = appengine.OAuth2DecoratorFromClientSecrets(
    filename=CLIENT_SECRETS, 
    scope=SCOPES, 
    cache=memcache, 
    prompt='consent', 
) 

:

을 내가 /auth.py했습니다

class Landing(webapp2.RequestHandler): 
    @auth.decorator.oauth_aware 
    def get(self): 
     if auth.decorator.has_credentials(): 
      self.redirect('/in') 
     else: 
      self.response.out.write(''' 
      etc. {}'''.format(auth.decorator.authorize_url())) 

class Main(webapp2.RequestHandler): 
    @auth.decorator.oauth_required 
    def get(self): 
     links = { ... } 
     render(self, 'base.html', template_values=links) 

class Calendar(webapp2.RequestHandler): 
    @auth.decorator.oauth_required 
    def get(self): 
     service = build('calendar', 'v3', http=auth.decorator.http()) 
     api_request = service.events().list(calendarId='primary') 
     api_response = api_request.execute() 
     self.response.headers['Content-Type'] = 'application/json; charset=utf-8' 
     self.response.out.write(json.dumps(api_response, indent=4)) 

class PutEvent(webapp2.RequestHandler): 
    @auth.decorator.oauth_required 
    def post(self): 
     # ... 
     # http = httplib2.Http(memcache) 
     service = build('calendar', 'v3') #, http=http) 

     api_response = [] 
     for i in json.loads(self.request.get('events')): 
      # ... 
      event = { ... } # Google Calendar event 
      api_request = service.events().insert(calendarId='primary', body=scadenza) 
      api_response.append(api_request.execute(http=auth.decorator.http())) 

     self.response.headers['Content-Type'] = 'application/json; charset=utf-8' 
     self.response.out.write(json.dumps(api_response, indent=4)) 

당신이 볼 수 있듯이 이것은 매우 간단하다 post이 Ajax jQuery 호출에 의해 요청되었습니다 ($.post('{{ putEvent_url }}', jsonData, function(data){ console.log(data); }) ...

저는 개발 서버에서 0123을 사용하고 있습니다.사용자가 앱에 내 개인 계정의 Google 캘린더에 액세스 할 권한이 있습니다. 나에게

이상한 일이 어떤 호출이 예상대로 작동) (달력,하지만 ERROR 500에서 PutEvent() 마지막에 호출하는 것입니다. 콘솔의 역 추적의 끝을 찾고

:

File "/home/pierpaolo/Devnos/whiterabbit/include/oauth2client/contrib/appengine.py", line 644, in check_oauth 
    resp = method(request_handler, *args, **kwargs) 
    File "/home/pierpaolo/Devnos/whiterabbit/main.py", line 211, in post 
    api_response.append(api_request.execute(http=auth.decorator.http())) 
    File "/home/pierpaolo/Devnos/whiterabbit/include/oauth2client/_helpers.py", line 133, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/home/pierpaolo/Devnos/whiterabbit/include/googleapiclient/http.py", line 838, in execute 
    raise HttpError(resp, content, uri=self.uri) 
HttpError: <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json returned "Forbidden"> 
INFO  2017-01-04 15:13:32,385 module.py:788] default: "POST /api/put/scadenze HTTP/1.1" 500 - 

내가 이해할 수없는

HttpError : https://www.googleapis.com/calendar/v3/calendars/primary/ events? alt = json이 "금지됨">을 반환했습니다.

나는 이미 내 계정에 대한 응용 프로그램 액세스 권한을 부여 받았으며 Google App Engine 데코레이터는에 따라 OAuth2.0을 만들기 위해 올바르게 배치되었습니다....

편집 :

 HTML/JS   GAE/Py 
+------------------+ 
|     | 
| <form>   | 
| ...data  | 
| <\JS/Ajax  | 
| $.post(...data | --> GAE/main.py 
|     |   @auth.decorator.oauth_required 
|     |   def post(self, data): 
+------------------+   event = elaborate(data) 
           service = build('calendar', 'v3') 
           api_request = service.events() 
              .insert(calendarId='primary', 
                body=event) 
           api_response = api_request 
               .execute(auth.decorator 
                  .http()) 
           self.response(api_response) 

편집 : 3 : 나는 oauth2client에 비트를 보았다 내 문제는 내가 구글 캘린더 API를 호출하는 방식과 관련이있을 수있는 경우 궁금 해서요 .contrib.appengine과 나는 logger.debug을 여기 저기에 추가했다 : 나는 문제가 execute(http=decorator.http()) 전화에있을 수 있다고 생각하지만, 내 다른 처리기에서 동일하다! 둘 다 위치 나 키워드도 ... ... 서비스 build 버릇이 변경에

을 authrized HTTP를 넣어 아니다 나는 _helpers.py", line 133, in positional_wrapper 초래할 수 있습니다 어떤 문제를 볼 수 있습니다

친애하는 모두에 대한 몇 가지 힌트 방법을 더 연구 없습니다?

사실, ACL을 삽입 및/또는 이벤트와 금지의 예외()를 던져 같은 RequestHandler를에 보조 달력을 삽입 할 수 있습니다. 삽입() ...!

+0

@everyone : 동일한 코드가 userinfo.profile 및 calendar (events.list)의 성공과 함께 작동합니다. 어떤 아이디어입니까? – user2154587

답변

0

에, 머리/체크 취소하려면, 문제는

내가 구글-API - 파이썬 클라이언트 GitHub의 추적에 문제를 열었다 ... endTimeUnspecified: True와 하루 종일 이벤트를 삽입하는 것입니다 : https://github.com/google/google-api-python-client/issues/334.

어쩌면 누군가가 조사하거나보다 정확한 답변을 게시 할 것입니다.

감사합니다.

0

그래서 난 그냥 대답으로 떠날거야 언급을 충분히 명성을 가지고하지 않은 :

첫째, 당신이 calandar API를 가지고 한 번 확인은 둘째 https://console.cloud.google.com/apis/dashboard?project=yourproject

활성화. 연락처 API를 사용하여 액세스 권한을 부여한 후에는 처음 허용 한도를 취소하지 않으면 액세스 권한을 다시 부여 할 수 없음을 알았습니다. 사용자가 내 앱을 Google 주소록에 연결 한 다음 연결을 끊은 다음 다시 연결하려고 시도했을 때이 오류가 발생했습니다. 두 번째 다시 연결하면 실패합니다. 분명히 https://security.google.com/settings/security/permissions

+0

감사합니다. 하지만 나는 403 금지의 이유는 다소 내가 API를 호출하는 방법과 관련이 있다고 생각 : 나는 손실 쿠키/authorized_http/credential/뭐든 내가 파이썬 요청 처리기에 내 양식을 제출 후 그 기능에 실제로 다른 호출 요청을 위임한다고 생각 정교한 데이터로 구글 API. 그에 따라 질문을 편집 할 것입니다. – user2154587

+0

Absurd : 사실, Acl을 삽입하고/또는 Events(). For() ... With 금지 된 예외를 throw하는 동일한 RequestHandler에 보조 캘린더를 삽입 할 수 있습니다. 그러나, 내 APPEND APP에 의해 추가 된 두 번째 달력에는 사건을 삽입 할 수 없습니다 !! – user2154587