1

Here we see: https://developers.google.com/youtube/2.0/developers_guide_protocol_comments#Adding_a_comment

I need to do a request with XML API.

POST /feeds/api/videos/VIDEO_ID/comments HTTP/1.1
Host: gdata.youtube.com
Content-Type: application/atom+xml
Content-Length: CONTENT_LENGTH
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=DEVELOPER_KEY

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:yt="http://gdata.youtube.com/schemas/2007">
  <content>This is a crazy video.</content>
</entry>

What should I use for this?

4

2 回答 2

1

您可以使用cURL来执行此操作。

<?php
$data = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:yt="http://gdata.youtube.com/schemas/2007">
    <content>This is a crazy video.</content>
</entry>
XML;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER,
    array('Content-Type: application/atom+xml',
    'Authorization: Bearer ACCESS_TOKEN',
    'GData-Version: 2',
    'X-GData-Key: key=DEVELOPER_KEY'));
$re = curl_exec($ch);
curl_close($ch);
?>
于 2013-08-23T03:18:53.330 回答
1

您可能会发现使用其中一个客户端库而不是手动执行 POST 最容易,因为它将为您处理标头生成、身份验证和令牌,而不会带来很多麻烦。客户端库的列表在这里:

https://developers.google.com/youtube/code

例如,要使用 Python 客户端发表评论,它看起来像这样(假设您已经完成了身份验证步骤,客户端使这些步骤变得非常简单):

my_comment = 'what a boring test video'
video_id = '9g6buYJTt_g'
video_entry = yt_service.GetYouTubeVideoEntry(video_id=video_id)
yt_service.AddComment(comment_text=my_comment, video_entry=video_entry)

其他语言的客户端遵循相同的结构。

于 2013-08-23T04:08:39.867 回答