【发布时间】:2018-01-15 04:30:24
【问题描述】:
我正在尝试使用 NodeJS 服务器创建一个 youtube 播放列表。我已按照以下链接中的 Oauth 的 NodeJS 快速入门说明进行操作:https://github.com/youtube/api-samples/blob/master/javascript/nodejs-quickstart.js
通过这个链接,我也可以通过以下方法获取频道信息:
function getChannel(auth) {
var service = google.youtube('v3');
service.channels.list({
auth: auth,
part: 'snippet,contentDetails,statistics',
forUsername: 'GoogleDevelopers'
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var channels = response.items;
if (channels.length == 0) {
console.log('No channel found.');
} else {
console.log('This channel\'s ID is %s. Its title is \'%s\', and ' +
'it has %s views.',
channels[0].id,
channels[0].snippet.title,
channels[0].statistics.viewCount);
}
});
}
我现在正尝试通过我的服务器创建一个播放列表,但唯一可以参考如何完成此操作的是通过此 JavaScript 链接:https://github.com/youtube/api-samples/blob/master/javascript/playlist_updates.js
我已经从上面的代码中添加了这个方法到 nodejs-quickstart.js 来尝试完成它:
function createPlaylist() {
var request = gapi.client.youtube.playlists.insert({
part: 'snippet,status',
resource: {
snippet: {
title: 'Test Playlist',
description: 'A private playlist created with the YouTube API'
},
status: {
privacyStatus: 'private'
}
}
});
request.execute(function(response) {
var result = response.result;
if (result) {
playlistId = result.id;
$('#playlist-id').val(playlistId);
$('#playlist-title').html(result.snippet.title);
$('#playlist-description').html(result.snippet.description);
} else {
$('#status').html('Could not create playlist');
}
});
}
我在将其转换为 NodeJS 示例时遇到问题,因为 JS 方法中没有发生身份验证,并且由于 nodeJS 快速入门示例中不存在/未提及“gapi”和“client”。有人可以帮忙把这个 JS 方法翻译成 nodeJS 吗?
【问题讨论】:
标签: javascript node.js youtube-api youtube-data-api