YouTube V3 API无法对视频进行排序

时间:2019-03-18 19:38:20

标签: python youtube-data-api pytube

所以我一直在使用youtube api抓取频道。直到3天前(03/15/2019)为止,一切都运转良好,结果不再排序。似乎无论我在order参数中输入什么,结果都是一样的。谁能告诉我为什么它不起作用?这是代码段:

import re
import os
import json
import MySQLdb
from pytube import YouTube
import urllib
import isodate
import sys

def get_all_video_in_channel(channel_id):
    api_key = '<MY KEY>'
    video_url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id={}&key={}'
    first_url = 'https://www.googleapis.com/youtube/v3/search?key={}&channelId={}&part=snippet,id&order=date&maxResults=50'.format(api_key, channel_id) #order by date but won't work

    res = []
    url = first_url
    while True:
        inp = urllib.urlopen(url)
        resp = json.load(inp)
        vidIds = []
        for jobject in resp['items']:
            if jobject['id']['kind'] == "youtube#video":
                vidIds.append(jobject['id']['videoId'])

        vidreq = urllib.urlopen(video_url.format(",".join(vidIds),api_key))
        vidres = json.load(vidreq)
        for vidjson in vidres['items']:
            res.append(vidjson)
        if (len(res) >= 50):
            break
        try:
            next_page_token = resp['nextPageToken']
            url = first_url + '&pageToken={}'.format(next_page_token)
        except:
            break

    return res

c_id = 'UCycyxZMoPwg9cuRDMyQE7PQ'
episodes = get_all_video_in_channel(c_id)

编辑:我做了一些研究,人们说API确实不能正常工作,这是因为Youtube删除了新西兰的拍摄视频,并且很快它将再次正常工作。

1 个答案:

答案 0 :(得分:0)

我建议您查看答案https://stackoverflow.com/a/55220182/8327971。这是Google已知和公认的问题:https://issuetracker.google.com/issues/128673552