Python HTTPError 401与谷歌幻灯片API&;应用程序引擎上的OAuth2

Python HTTPError 401与谷歌幻灯片API&;应用程序引擎上的OAuth2,python,google-app-engine,google-oauth,google-slides-api,Python,Google App Engine,Google Oauth,Google Slides Api,我试图在Google App Engine上使用Google Slides API,尽管使用了Google代码示例(特别是针对OAuth2和App Engine上的Slides API),我还是遇到了问题 这是我的应用程序引擎代码,删除了不必要的积垢(一切都在main.App中)。我正在做的是尝试从HTML表单发布一个字符串,然后构建一个空白的演示文稿。我已经将SlidesAPI与一个简单的脚本一起使用,我制作了原型;我现在正试图通过一个应用程序引擎应用程序实现这种自助服务,但身份验证方面的变化

我试图在Google App Engine上使用Google Slides API,尽管使用了Google代码示例(特别是针对OAuth2和App Engine上的Slides API),我还是遇到了问题

这是我的应用程序引擎代码,删除了不必要的积垢(一切都在main.App中)。我正在做的是尝试从HTML表单发布一个字符串,然后构建一个空白的演示文稿。我已经将SlidesAPI与一个简单的脚本一起使用,我制作了原型;我现在正试图通过一个应用程序引擎应用程序实现这种自助服务,但身份验证方面的变化让我大吃一惊

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服务器上;但也在live app上)是:

回溯(最近一次呼叫最后一次):
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/lib/webapp2-2.5.2/webapp2.py”,第1535行,在调用中__
rv=自身处理异常(请求、响应、e)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/lib/webapp2-2.5.2/webapp2.py”,第1529行,在__
rv=自我路由器调度(请求、响应)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/lib/webapp2-2.5.2/webapp2.py”,第1278行,默认为
返回路由处理程序适配器(请求、响应)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/lib/webapp2-2.5.2/webapp2.py”,第1102行,在__
返回处理程序.dispatch()
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py”,第572行,在调度中
返回self.handle_异常(e,self.app.debug)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py”,第570行,在调度中
返回方法(*args,**kwargs)
文件“/Users/jedc/pm-tools/oauth2client/contrib/appengine.py”,第644行,检查oauth
resp=方法(请求处理程序,*args,**kwargs)
文件“/Users/jedc/pm-tools/main.py”,第113行,在post中
presentation=service.presentations().create(body=presentationbody.execute())
文件“/Users/jedc/pm-tools/oauth2client/_-helpers.py”,第133行,在位置包装中
已包装退货(*args,**kwargs)
文件“/Users/jedc/pm-tools/googleapiclient/http.py”,第840行,在execute中
raise HttpError(resp,content,uri=self.uri)
HttpError:

我觉得我在这里做了一些微妙但愚蠢的事情。如果有人能帮我弄清楚这是什么,我将不胜感激

发生此错误是因为您的http没有使用凭据进行授权。 要使用凭据对http进行授权,您应该使用decorator

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)
这会解决你的问题。 供谷歌进一步参考

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)