我怎么能通过php api更新youtube视频?

时间:2012-11-16 15:11:04

标签: php api youtube

我将使用以下代码更新视频:

$headers = array("PUT /feeds/api/users/default/uploads/VIDEOID HTTP/1.1",
"Host: gdata.youtube.com",
"Authorization: GoogleLogin auth=".$authvalue,
"GData-Version: 2",
"X-GData-Key: key=KEY",
"Content-length: ".strlen($data),
"Content-Type: application/atom+xml; charset=UTF-8");
$curl = curl_init("https://gdata.youtube.com/feeds/api/users/default/uploads/VIDEOID");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_REFERER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
$returnxxx = curl_exec($curl);
curl_close($curl);
echo $returnxxx;

我已经生成了一个valide authvalue(测试它 - > ok)。但它显示:

  

无效的uri

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

@Marc B感谢您的提示! 我使用了curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');而不是curl_setopt($curl, CURLOPT_POST, 1);