Google App Engine Python - YouTube API v3 - 权限不足

时间:2015-06-13 17:43:03

标签: python google-app-engine oauth-2.0 youtube-api google-oauth2

我成功地从this视频复制了任务API,但我无法将此格式成功转换为使用YouTube API。

这是我的.py文件:

import httplib2
import os
import sys
import jinja2
import webapp2
import logging
import pprint

from oauth2client import tools
from oauth2client.client import flow_from_clientsecrets
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.client import AccessTokenRefreshError
from oauth2client.tools import argparser, run_flow
from oauth2client.appengine import OAuth2Decorator

from apiclient.discovery import build
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template

decorator = OAuth2Decorator(
    client_id = '*my client ID*',
    client_secret = '*my client secret*',
    scope='https://www.googleapis.com/auth/youtube')

service = build("youtube", "v3")

class MainHandler(webapp2.RequestHandler):
    @decorator.oauth_required
    def get (self):
        self.response.headers['Content-Type'] = 'text/plain'

        channels_list = service.channels().list(
            mine=True,
            part="id"
        ).execute(http = decorator.http())
        self.response.out.write (pprint.pformat(channels_list))


app = webapp2.WSGIApplication (
        [
            ('/', MainHandler),
            (decorator.callback_path, decorator.callback_handler()),
        ], 
        debug=True)

这是我的追溯:

Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__

    rv = self.handle_exception(request, response, e)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__

    rv = self.router.dispatch(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher

    return route.handler_adapter(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__

    return handler.dispatch()

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch

    return self.handle_exception(e, self.app.debug)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch

    return method(*args, **kwargs)

  File "C:\Users\...\testapp\oauth2client\appengine.py", line 733, in check_oauth

    resp = method(request_handler, *args, **kwargs)

  File "C:\Users\...\testapp\testapp.py", line 35, in get

    ).execute(http = decorator.http())

  File "C:\Users\...\testapp\oauth2client\util.py", line 129, in positional_wrapper

    return wrapped(*args, **kwargs)

  File "C:\Users\...\testapp\apiclient\http.py", line 723, in execute

    raise HttpError(resp, content, uri=self.uri)

HttpError: <HttpError 403 when requesting https://www.googleapis.com/youtube/v3/channels?part=id&mine=true&alt=json returned "Insufficient Permission">

INFO     2015-06-13 12:27:54,515 module.py:788] default: "GET / HTTP/1.1" 500 2278

我已检查并仔细检查我是否同时启用了YouTube数据API和YouTube Analytics API此客户端ID。我甚至已禁用它们并重新启用以进行检查,但我仍然收到此错误。

我是GAE及其方法的新手,所以也许我不理解Traceback中的错误。

需要注意的是,我为apiclient,httplib2,oauth2client和uritemplate收到了“ImportError:No module named ...”,所以我将这些文件夹直接移到我的app文件中(并没有再次出现错误) 。不确定是否将它们直接移动到文件夹中会导致错误。

1 个答案:

答案 0 :(得分:0)

好吧,我希望我没有浪费任何人的时间,但如果有其他人有这个问题,我发现this问题,虽然我没有记忆问题,我从我正在使用的用户帐户中撤消了对我的应用的权限,刷新了应用并再次获得了许可,现在它似乎正在运行。

我猜这是谷歌方面的问题。感谢任何花时间阅读我的问题的人。