我正在做一个项目,使用forUsername参数和youtube-data-api,通过传统用户名获取频道上传播放列表的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()发布于 2022-11-06 10:40:16
如果我错了,纠正我,但是你提供的播放列表是无效的,不管怎么样?它根本不存在。您提供的播放列表ID为24个字符,与我在进入您所描述的曼彻斯特联队频道时发现的32个字符播放列表ID不同。
例如,https://www.youtube.com/playlist?list=PL5-QUghxmluKZGNgKiJPctZl2hgar88Hq
https://stackoverflow.com/questions/74331394
复制相似问题