사소한 일이되어야하지만 해결할 수는 없습니다.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를에 보조 달력을 삽입 할 수 있습니다. 삽입() ...!
@everyone : 동일한 코드가 userinfo.profile 및 calendar (events.list)의 성공과 함께 작동합니다. 어떤 아이디어입니까? – user2154587