2

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:

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.

4

1 回答 1

4

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

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

另请注意,我已将对象更改为使用双引号,因为options.resource预期是有效的 JSON。我还删除了该status属性,因为它未在 API 参考页面上列为参数 - https://developers.google.com/youtube/v3/docs/playlistItems/insert

于 2014-11-22T07:25:50.717 回答