我想用google-api-nodejs-client
在YouTube视频上发表评论。知道怎么做吗?
如果能提供一个代码示例,我将非常感激。
谢谢!
我做到了!
这里是代码,以防有人正在寻找答案。
var oauth2Client = new OAuth2("CLIENT_ID", "CLIENT_SECRET", []),
google = require('googleapis'),
ytdapi = google.youtube('v3');
oauth2Client.setCredentials({
refresh_token: "REFRESH_TOKEN"
});
var params = {
auth: oauth2Client,
part: "snippet",
resource: {
snippet: {
channelId: "CHANNEL_ID",
videoId: "VIDEO_ID",
topLevelComment: {
snippet: {
textOriginal: "YOUR TEXT HERE"
}
}
}
}
};
ytdapi.commentThreads.insert(params, function(err, data) {
if (err) {
console.log(err);
res.status(400).send("Error posting comment ");
}
else {
console.log(data);
res.status(200).send("Successfully posted comment ");
}
});