我在本地主机上有一个页面,用户可以从这里上传视频。现在我想实现的功能,管理员可以使这些视频公开(用户必须上传它们作为私人视频)。现在,首先,我需要得到一个列表上的所有视频频道(包括私人的)。我试过这个代码:
$data = '<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
</entry>';
$headers = array( "Authorization: GoogleLogin auth=".$authvalue,
"GData-Version: 2",
"X-GData-Key: key=".$youtube_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");
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_FOLLOWLOCATION, 1 );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
curl_setopt( $curl, CURLOPT_REFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $curl, CURLOPT_HEADER, 0 );
$response = curl_exec($curl);
curl_close($curl);
返回错误:
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:....
我找不到请求用户视频列表的适当形式的标题,所以我使用了我申请上传视频的标题(并且有效,所以我确信用户认证没有问题)。
如果你能告诉我我做错了什么,或者只是指给我一个工作视频列表的例子,我将非常感激。
编辑:Curl_error返回空字符串,curl_info返回this:
array (size=26)
'url' => string 'https://uploads.gdata.youtube.com/feeds/api/users/.../uploads' (length=80)
'content_type' => string 'text/html; charset=UTF-8' (length=24)
'http_code' => int 400
'header_size' => int 597
'request_size' => int 1747
'filetime' => int -1
'ssl_verify_result' => int 20
'redirect_count' => int 1
'total_time' => float 0.639
'namelookup_time' => float 0.047
'connect_time' => float 0.078
'pretransfer_time' => float 0.172
'size_upload' => float 0
'size_download' => float 925
'speed_download' => float 1447
'speed_upload' => float 0
'download_content_length' => float 925
'upload_content_length' => float 0
'starttransfer_time' => float 0.203
'redirect_time' => float 0.436
'certinfo' =>
array (size=0)
empty
'primary_ip' => string '173.194.70.117' (length=14)
'primary_port' => int 443
'local_ip' => string '10.0.0.33' (length=9)
'local_port' => int 53639
'redirect_url' => string '' (length=0)
参考上面的注释,安装带有Zend_Gdata (version>= 1.7.7)扩展的Zend库解决了这个问题。还注意PHP版本必须>= 5.1.4。
参考:Google YouTube API - PHP
我认为你必须尝试php修剪函数的每一个参数,你在这个cURL调用发送。像
"Authorization: GoogleLogin auth=".trim($authvalue),
"GData-Version: 2",
"X-GData-Key: key=".trim($youtube_key),
"Content-length: ".trim(strlen($data)),
应该能行