2013-08-23 3 views
1

여기에 표시됩니다 : https://developers.google.com/youtube/2.0/developers_guide_protocol_comments#Adding_a_commentXML API로 POST하는 방법은 무엇입니까?

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> 

무엇을 사용해야합니까?

답변

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); 
?> 
1

당신은 가능성이, 클라이언트 라이브러리 중 하나를 사용하는 대신 수동으로 POST를 할 그것을 가장 쉽게 찾을 수 있습니다. 클라이언트 라이브러리의 목록은 여기에 있습니다 :

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

예를 들어, 파이썬 클라이언트에 코멘트 게시물을 할, 당신이 인증 단계를 모두 거라고 가정이 뭔가를 (어느 보일 것이다 클라이언트는 매우 간단합니다.)

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) 

다른 언어의 클라이언트는 동일한 구조를 따릅니다.

+0

nice! 내가 죽었다고 생각하면 XML 지옥을 통과해야 해! – sirvon

관련 문제