我正在嘗試在YouTube視頻上發佈評論...爲此,我使用YouTube api。下面是代碼:爲什麼這個CURL請求不起作用?
<?php
$message="Just Some Comment...";
$developer_key="<!---visit demo for actual code---!>";
$access_token=$_GET['code'];
if(!$access_token){ Header("Location: <!---visit demo for actual code---!>");}
$video_id="I3LMKhu2-vo";
$message_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>' . $message . '</content>
</entry>';
$url = "http://gdata.youtube.com/feeds/api/videos/" . $video_id . "/comments";
$header = array('Content-Type: application/atom+xml', 'Content-Length: ' . strlen($message_xml), 'Authorization: Bearer "' . $access_token . '"', 'GData-Version: 2', 'X-GData-Key: key=' . $developer_key);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$message_xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
echo $access_token;
?>
如果我引用這是隱藏個人的東西,但你可以在votm.net78.net 看到演示所以我的問題是,爲什麼不評論出現在視頻,即使用戶已經發送授權令牌?請問我可以幫忙嗎?謝謝!
'$ result'中有什麼?如果在'$ result = curl_exec($ ch);'後面加上'var_dump($ result);',你會看到什麼? – 2013-04-01 07:34:35