0

Google App Engine에서 Google 슬라이드 API를 사용하려고하는데 Google 코드 샘플 (특히 OAuth2 & App Engine의 Slides API)을 사용하고 있음에도 불구하고 문제가 생겼어.App Engine의 Google 슬라이드 API 및 OAuth2가 포함 된 HTTPError

여기 내 App Engine 코드입니다. 불필요한 코드가 제거되었습니다 (모든 것이 main.app에 있음). 내가하고있는 일은 HTML 폼에서 문자열을 게시 한 다음 빈 프레젠테이션을 만드는 것입니다. 저는 이미 프로토 타입을 작성한 간단한 스크립트로 Slides API를 사용했습니다. 지금은 App Engine 앱을 통해이 셀프 서비스를 제공하려고 노력하고 있지만 인증을 변경하면 나를 방해 할 수 있습니다.

from googleapiclient import discovery 
from oauth2client import client 
from oauth2client.contrib import appengine 
from google.appengine.api import memcache 

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json') 
MISSING_CLIENT_SECRETS_MESSAGE = """[omitted]""" % CLIENT_SECRETS  

http = httplib2.Http() 
service = discovery.build('slides', 'v1', http=http) 
decorator = appengine.OAuth2DecoratorFromClientSecrets(
    CLIENT_SECRETS, 
    scope='https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/drive', 
    message=MISSING_CLIENT_SECRETS_MESSAGE) 

class SlideBuilder(webapp2.RequestHandler): 

    @decorator.oauth_required 
    def post(self): 
    programslug = self.request.get('programid') 
    presoname = str(programslug) + ' Mentors' 

    presentationbody = { 
     'title': presoname 
    } 
    presentation = service.presentations().create(body=presentationbody).execute() 

나는 내가 API 콘솔에서 직접 가장 최근의 client_secrets.json 다운로드 지적하고 싶은, 그래서 CLIENT_SECRETS에 대해 올바르게 일치해야합니다. ;

내가지고있어 오류 (dev에 서버에 있지만 라이브 응용 프로그램에이기도합니다)이있다 : 여기하고있어 미묘한하지만 바보가있는 것

Traceback (most recent call last): 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__ 
    return handler.dispatch() 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch 
    return method(*args, **kwargs) 
    File "/Users/jedc/pm-tools/oauth2client/contrib/appengine.py", line 644, in check_oauth 
    resp = method(request_handler, *args, **kwargs) 
    File "/Users/jedc/pm-tools/main.py", line 113, in post 
    presentation = service.presentations().create(body=presentationbody).execute() 
    File "/Users/jedc/pm-tools/oauth2client/_helpers.py", line 133, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/Users/jedc/pm-tools/googleapiclient/http.py", line 840, in execute 
    raise HttpError(resp, content, uri=self.uri) 
HttpError: <HttpError 401 when requesting https://slides.googleapis.com/v1/presentations?alt=json returned "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."> 

느낀다. 그게 뭔지 알아 내려고 어떤 도움이나 포인터를 주셔서 감사합니다!

답변

0

http가 자격 증명으로 인증되지 않았기 때문에이 오류가 발생합니다. 자격 증명으로 http를 인증하려면 데코레이터를 사용해야합니다.

decorator = appengine.OAuth2DecoratorFromClientSecrets(
    CLIENT_SECRETS, 
    scope='https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/drive', 
    message=MISSING_CLIENT_SECRETS_MESSAGE) 
http = decorator.http() 
service = discovery.build('slides', 'v1', http=http) 

이렇게하면 문제가 해결됩니다. 자세한 내용은 read this app engine decorators documentation Google에서