所以我从youtube api中获得了意想不到的行为 -
class youtube:
def __init__(self):
#self.youtube= YoutubeAPI('AIzaSyCoCdD-vL2zNIlQvNARXKXltqKIXcNJ6MA')
self.api_key=my_number
def channel_id(self,name):
string= "https://www.googleapis.com/youtube/v3/channels?key=" + self.api_key + "&forUsername=" +name + "&part=id"
r=requests.get(string)
data=json.loads(r.text)
chan_id_list= data["items"][0]
chan_id = chan_id_list["id"]
return chan_id
def is_live(self,channels_id):
string = "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId="+ channels_id+ "&type=video&eventType=live&key=" + self.api_key
r=requests.get(string)
data = json.loads(r.text)
print data
x=youtube()
x.is_live(x.channel_id("WWE"))
print x.channel_id("WWE")
当我运行代码时,我得到了这个输出
{u'regionCode': u'US', u'kind': u'youtube#searchListResponse', u'etag': u'"m2yskBQFythfE4irbTIeOgYYfBU/-f6JA5_OcXz2RWuH1mpAA2_9mM8"', u'pageInfo': {u'resultsPerPage': 5, u'totalResults': 0}, u'items': []}
UC2Oxk5J24C1gYhDWpRDNPlw
我得到了回复,但它是空的。我觉得我错过了一些微不足道的东西。有谁知道发生了什么?