我才刚刚开始学习编程(和python,flask),我有一个情况,我不能自己解决(或使用谷歌)。
我正在尝试通过youtube data v3访问我的youtube频道数据,并使用google官方库进行oauth和数据检索。
下面的代码就是我使用的代码。该方法的返回运行良好,但是它只在我的浏览器中呈现json响应,我不能‘捕获’并处理它。
@app.route('/')
def index():
if 'credentials' not in flask.session:
return flask.redirect('authorize')
credentials = google.oauth2.credentials.Credentials(
**flask.session['credentials'])
client = googleapiclient.discovery.build(
API_SERVICE_NAME, API_VERSION, credentials=credentials)
return channels_list_by_username(client,
part='snippet,contentDetails,statistics',
forUsername='username')我想把调用放在一个新的变量中,json.dump()-ing响应,并像这样访问它,但它就是不起作用。
在这方面的任何帮助都是非常感谢的。谢谢!
发布于 2019-01-08 03:25:30
您可以将该调用的结果存储到一个变量中,对其进行处理,然后返回
@app.route('/')
def index():
if 'credentials' not in flask.session:
return flask.redirect('authorize')
credentials = google.oauth2.credentials.Credentials(
**flask.session['credentials'])
client = googleapiclient.discovery.build(
API_SERVICE_NAME, API_VERSION, credentials=credentials)
# Here is your variable
channels = channels_list_by_username(client,
part='snippet,contentDetails,statistics',
forUsername='username')
# Process it
print(channels)
# Add other processing stuff here
# Return it
return channelshttps://stackoverflow.com/questions/54080493
复制相似问题