我一直试图返回列表,以便其他功能可以访问它。但是在所有其他函数中,变量变得不确定。命令应该是“ return twitchClipLinks”吧?
def api():
#API via twitch to get the top clips of Just Chatting
API_ENDPOINT = 'https://api.twitch.tv/kraken/clips/top?game=Just%20Chatting&period=day&trending=false&limit=6'
ID = 'REMOVED'
auth = 'application/vnd.twitchtv.v5+json'
head = {
'Client-ID' : ID,
'Accept' : auth
}
r = requests.get(url = API_ENDPOINT, headers = head)
twitchClipLinks = []
data = r.json()
for link in data['clips']:
store = str(link['url'])
twitchClipLinks.append(store)
return twitchClipLinks
答案 0 :(得分:1)
在每个函数中,您必须添加以下内容:twitchClipLinks = api()
或可以将twitchClipLinks
定义为global variable
并从您的{{1 }}功能。