Я пытаюсь подключиться к своему веб-приложению и получаю внутреннюю ошибку сервера после загрузки через localhost.
import json
import flask
import httplib2
from apiclient import discovery
from oauth2client import client
app = flask.Flask(__name__)
@app.route('/')
def index():
if 'credentials' not in flask.session:
return flask.redirect(flask.url_for('oauth2callback'))
credentials = client.OAuth2Credentials.from_json(flask.session['credentials'])
if credentials.access_token_expired:
return flask.redirect(flask.url_for('oauth2callback'))
else:
http_auth = credentials.authorize(httplib2.Http())
youtube = discovery.build('youtubeAnalytics', 'v1', http_auth)
report = youtube.reports().query(ids='channel==MINE', start_date='2019-03-01', end_date='2019-03-20', metrics='views').execute()
return json.dumps(report)
@app.route('/oauth2callback')
def oauth2callback():
flow = client.flow_from_clientsecrets(
'client_secrets.json',
scope='https://www.googleapis.com/auth/yt-analytics.readonly',
redirect_uri=flask.url_for('oauth2callback', _external=True),
include_granted_scopes=True)
if 'code' not in flask.request.args:
auth_uri = flow.step1_get_authorize_url()
return flask.redirect(auth_uri)
else:
auth_code = flask.request.args.get('code')
credentials = flow.step2_exchange(auth_code)
flask.session['credentials'] = credentials.to_json()
return flask.redirect(flask.url_for('index'))
if __name__ == '__main__':
import uuid
app.secret_key = str(uuid.uuid4())
app.debug = False
app.run()
У меня есть файл client_secret в моем текущем каталоге со всем современным, однако я все еще продолжаю сталкиваться с этой проблемой.