Post 通过 curl 对 youtube 视频发表评论

Post comment on youtube video by curl

我正在做一个 YouTube 应用项目。但我无法 post 对任何视频发表评论。我正在使用 curl 和 php。我已经正确地设置了所有功能,但是显示了某种错误 如果我使用

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);

其中 $data_json

    {
    "snippet": {
  "topLevelComment": {
   "snippet": {
    "videoId": "<?php echo $videoid; ?>",
    "textOriginal": "<?php echo $comment; >"
   }
  }
 }
}

 { "error": { "errors": [ { "domain": "global", "reason": "parseError",                                   
 "message": "This API does not support parsing form-encoded input." } ],  
 "code":    400, "message": "This API does not support parsing form-encoded
 input." } }

请帮帮我。

您需要提及您的 content-type header 以便 youtube 知道您发送的是什么。默认情况下,您现在正在使用 form-encoded 输入。

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));