如何使用 Google 的 API 为 PHP 插入 Youtube 评论?

How to insert Youtube comment using Google's API for PHP?

我为 PHP 安装了最新版本的 Google API。使用列出的示例 here,我尝试为视频插入评论。但是,它失败了:

Warning: require_once(/var/www/html/youtube/vendor/google/apiclient/src/Google/Service/YouTube.php): failed to open stream: No such file or directory in /var/www/html/youtube/vendor/google/apiclient/examples/comment_threads.php on line 15

Fatal error: require_once(): Failed opening required '/var/www/html/youtube/vendor/google/apiclient/src/Google/Service/YouTube.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/youtube/vendor/google/apiclient/examples/comment_threads.php on line 15

这是有道理的,因为给定位置的服务文件夹中没有文件 'Youtube.php'。代码暗示应该有,所以恐怕这些例子已经过时了。我正在使用 Google API PHP 的 2.0.0@RC 版本(这似乎是最新的)。所以,我的问题是:示例是否已过时(如果是,我应该如何插入 Youtube 评论?),或者示例是否还不错,我是不是做错了什么?

您可以查看此 documentation 如何在 YouTube 中添加评论 API。

下面的code sample演示了如何使用下面的API方法来创建和管理评论:

  • 它调用 commentThreads.list 方法并设置 videoId 参数来检索视频评论。

  • 它调用 comments.insert 方法并设置 parentId 参数以回复现有评论。

  • 它使用parentId参数调用comments.list方法来检索线程中的评论。

  • 调用请求体中带评论的comments.update方法更新评论

  • 调用comments.setModerationStatus方法设置评论审核状态,comments.markAsSpam方法将评论标记为垃圾评论,comments.delete方法删除评论,使用id参数标识评论。

另请查看此 SO question 了解更多信息。