You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用YouTube Data API playlistItems接口持续返回400错误求助

解决YouTube Playlist Items插入的400错误

问题原因

YouTube Data API的playlistItems.insert接口要求必须在请求URL的查询参数中指定part参数,用来声明你要提交的资源部分。你的请求缺少这个必填参数,导致API误判,抛出unexpectedPart错误。

解决方法

在请求URL的查询参数中添加part: 'snippet'(因为你在请求体中提交的是snippet相关数据),修改后的代码如下:

request.post({
    url: 'https://youtube.googleapis.com/youtube/v3/playlistItems?' + querystring.stringify({
        key: google_api,
        part: 'snippet' // 新增必填的part参数
    }),
    headers: {
        'Authorization': 'Bearer ' + tokens.access_token,
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    json: {
        "snippet": {
            "playlistId": storedsessions[state]["yt-playlist"],
            "resourceId": {
                "kind": "youtube#video",
                "videoId": json["items"][0]["id"]["videoId"]
            }
        }
    }
})

说明

part参数是YouTube Data API的核心必填项,它明确告诉API你要操作资源的哪些字段集合。当你在请求体中提交snippet结构的数据时,必须在URL参数中声明part=snippet,这样API才能正确解析你的请求内容,避免参数识别错误。

内容的提问来源于stack exchange,提问作者luucc_ss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 03:30:34