playlistItems。在节点插入失败。js googleapi youtube

时间:2022-08-11 15:47:27

I am uploading a video to Youtube and then attempting to add it to a playlist. The playlist insert is failing in a weird way. Here is my code:

我把一个视频上传到Youtube上,然后试图把它添加到播放列表中。播放列表插入以一种奇怪的方式失败。这是我的代码:

var options = {
                    'part'  : 'snippet',
                    'snippet'   : {
                        'playlistId'    : playlistId,
                        'resourceId'    : {
                            'kind'      : 'youtube#video',
                            'videoId'   : videoId
                        }
                    },
                    status  : {
                        privacyStatus   : 'unlisted'
                    }
                };

            console.log('options : ' + JSON.stringify(options));

            youtube.playlistItems.insert(options, function(listErr, listResponse){

                console.log(JSON.stringify(listErr));
                console.log(JSON.stringify(listResponse));

            });

I always get the exact same response:

我总是得到相同的回答:

{"errors":[{"domain":"youtube.playlistItem","reason":"playlistIdRequired","message":"Playlist id not specified."}],"code":400,"message":"Playlist id not specified."}

Anyone have any idea what I'm doing wrong? Any help will be much appreciated. I'm using googleapi Node.js sdk.

有人知道我做错了什么吗?如有任何帮助,我们将不胜感激。我用googleapi节点。js sdk。

1 个解决方案

#1


4  

I was having a similar issue and inspected the source code and realised that the body of an API call should be under options.resource property. So your options object should look like the following:

我遇到了类似的问题,检查了源代码,并意识到API调用的主体应该位于选项之下。资源属性。因此,您的options对象应该如下所示:

var options = {
    "part"  : "snippet",
    "resource" : {
        "snippet" : {
            "playlistId" : playlistId,
            "resourceId" : {
                "kind" : "youtube#video",
                "videoId" : videoId
                }
            }
        }
    }

Also note that I've changed the object to use double-quotation marks, as options.resource is expected to be valid JSON. I've also removed the status property as it is not listed as a parameter on the API reference page - https://developers.google.com/youtube/v3/docs/playlistItems/insert

还要注意,我已经将对象更改为使用双引号作为选项。资源应该是有效的JSON。我还删除了status属性,因为它没有作为API引用页面的参数列出——https://developers.google.com/youtube/v3/docs/playlistItems/insert

#1


4  

I was having a similar issue and inspected the source code and realised that the body of an API call should be under options.resource property. So your options object should look like the following:

我遇到了类似的问题,检查了源代码,并意识到API调用的主体应该位于选项之下。资源属性。因此,您的options对象应该如下所示:

var options = {
    "part"  : "snippet",
    "resource" : {
        "snippet" : {
            "playlistId" : playlistId,
            "resourceId" : {
                "kind" : "youtube#video",
                "videoId" : videoId
                }
            }
        }
    }

Also note that I've changed the object to use double-quotation marks, as options.resource is expected to be valid JSON. I've also removed the status property as it is not listed as a parameter on the API reference page - https://developers.google.com/youtube/v3/docs/playlistItems/insert

还要注意,我已经将对象更改为使用双引号作为选项。资源应该是有效的JSON。我还删除了status属性,因为它没有作为API引用页面的参数列出——https://developers.google.com/youtube/v3/docs/playlistItems/insert