将评论上传到YouTube-Laravel和PHP

时间:2019-08-20 17:28:43

标签: php youtube

我正在尝试通过youtube api v3将评论上传到视频上。我已经按照所有必需的步骤进行操作,但是在运行该函数时出现此错误:

  

“以空值调用成员函数insert()”

我在下面的代码中我可能做错什么?我还附上了commentThread身体反应的图像。

控制器

 public function postComment()
 { 
     $this->handleAccessToken();
     $commentText = 'Nature is very beautiful.';
     $videoId = '*******';
     // Define the $commentThread object, which will be uploaded as the request body.
     $commentThread = new Google_Service_YouTube_CommentThread();

     // Add 'snippet' object to the $commentThread object.
     $commentThreadSnippet = new Google_Service_YouTube_CommentThreadSnippet();
     $commentThreadSnippet->setChannelId('UCgRMq9VjnorQ37LGOda2Scw');
     $comment = new Google_Service_YouTube_Comment();
     $commentSnippet = new Google_Service_YouTube_CommentSnippet();
     $commentSnippet->setTextOriginal('Beautiful API');
     $comment->setSnippet($commentSnippet);
     $commentThreadSnippet->setTopLevelComment($comment);
     $commentThreadSnippet->setVideoId('eSHECqoAF08');
     $commentThread->setSnippet($commentThreadSnippet);

     // return $commentThread;

     $response = $this->youtube_comment->commentThreads->insert('snippet', $commentThread);

     return $response;
}

enter image description here

0 个答案:

没有答案