使用YouTube Data API获取频道播放列表时遇playlistNotFound错误
问题描述
我正在开发一个项目,使用Python3和YouTube Data API,通过频道的旧用户名(legacy username)及forUsername参数获取频道的上传播放列表ID,进而获取频道内的视频及所需信息。部分频道可正常运行,但部分频道会返回playlistNotFound错误——即便我打印确认获取到的playlistId无误。以ManchesterUnited频道的播放列表ID UUNbg-_aV3kK4MEb2vgdBtsw 为例,报错信息如下:
报错信息
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUNbg-_aV3kK4MEb2vgdBtsw&maxResults=50&key=AIzaSy...&alt=json returned "The playlist identified with the request's <code>playlistId</code> parameter cannot be found.". Details: "[{'message': "The playlist identified with the request's <code>playlistId</code> parameter cannot be found.", 'domain': 'youtube.playlistItem', 'reason': 'playlistNotFound', 'location': 'playlistId', 'locationType': 'parameter'}]">
我的代码
from scraper_api import ScraperAPIClient import requests import googleapiclient.discovery import html import gspread from oauth2client.service_account import ServiceAccountCredentials import json username=input("what is the channel username? (go to page and then you will see in the url) ") ytapi = requests.get("https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername="+username+"&key=AIzaSy...") print(ytapi.text) at=ytapi.text.split(' ') c=1 b=0 viewnumbers = [] titles = [] vtypes = [] urls = [] for i in at: c+=1 if 'uploads' in i: for it in at[c-3:]: if 'U' in it: print(it) idd=it[1:len(it)-2] print(idd) break playlist_id = idd youtube = googleapiclient.discovery.build("youtube", "v3", developerKey = "AIzaSy...") request = youtube.playlistItems().list( part = "snippet", playlistId = playlist_id, maxResults = 50 ) response = request.execute()
内容的提问来源于stack exchange,提问作者Sean Cassidy
相关产品推荐
相关产品推荐

