英文:
YouTube Data API playlistItems always returns 400
问题
I'm trying to add videos to a playlist the user entered from Node.JS, however, I always get this 400 code error:
{
"error":{
"code":400,
"message":"'snippet'",
"errors":[
{
"message":"'snippet'",
"domain":"youtube.part",
"reason":"unexpectedPart",
"location":"part",
"locationType":"parameter"
}
]
}
}
Here's the part of the code that adds the video to the playlist:
request.post({
url: 'https://youtube.googleapis.com/youtube/v3/playlistItems?' + querystring.stringify({
key: google_api
}),
headers: {
'Authorization': 'Bearer ' + tokens.access_token,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
json: {
"snippet": {
"playlistId": storedsessions[state]["yt-playlist"], // looks something like "PLk970BwgU6MkZpRtCnQqO43FHd7g7m_mn"
"resourceId": {
"kind": "youtube#video",
"videoId": json["items"][0]["id"]["videoId"] // looks something like "aHCtj4UTQgE"
}
}
}
})
Also, ignore the fact I'm using a deprecated module, I have to use it for another API I'm using and couldn't find much information on how to move to Axios or another better module (plus, it works perfectly, so I don't mind it); anyways, what can I do?
英文:
I'm trying to add videos to a playlist the user entered from Node.JS, however, I always get this 400 code error:
{
"error":{
"code":400,
"message":"'snippet'",
"errors":[
{
"message":"'snippet'",
"domain":"youtube.part",
"reason":"unexpectedPart",
"location":"part",
"locationType":"parameter"
}
]
}
}
Here's the part of the code that adds the video to the playlist:
request.post({
url: 'https://youtube.googleapis.com/youtube/v3/playlistItems?' + querystring.stringify({
key: google_api
}),
headers: {
'Authorization': 'Bearer ' + tokens.access_token,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
json: {
"snippet": {
"playlistId": storedsessions[state]["yt-playlist"], // looks something like "PLk970BwgU6MkZpRtCnQqO43FHd7g7m_mn"
"resourceId": {
"kind": "youtube#video",
"videoId": json["items"][0]["id"]["videoId"] // looks something like "aHCtj4UTQgE"
}
}
}
})
Also, ignore the fact I'm using a deprecated module, I have to use it for another API I'm using and couldn't find much information on how to move to Axios or another better module (plus, it works perfectly, so I don't mind it); anyways, what can I do?
答案1
得分: 0
我找到了需要添加的内容!我忘记将搜索参数 "part" 设置为 "snippet",下面是更新后的代码:
request.post({
url: 'https://youtube.googleapis.com/youtube/v3/playlistItems?' + querystring.stringify({
part: 'snippet',
key: google_api
}),
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"]
}
}
}
})
英文:
Found out what I needed to add! I forgot to set the search paramater "part" to "snippet", here's the updated code now:
request.post({
url: 'https://youtube.googleapis.com/youtube/v3/playlistItems?' + querystring.stringify({
part: "snippet",
key: google_api
}),
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"]
}
}
}
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论