如何在YouTube视频上发表评论? (Node.js的)

时间:2015-09-16 15:34:46

标签: node.js youtube youtube-api google-api-nodejs-client

我想使用google-api-nodejs-client以编程方式发布对YouTube视频的评论。任何想法我该怎么办?

如果提供代码示例,我将非常感激。

谢谢!

1 个答案:

答案 0 :(得分:3)

我设法做到了!

这是代码,以防有人在寻找答案。



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 ");
  }
});