php – YouTube API:错误400(错误请求)
发布时间:2020-12-13 22:46:55 所属栏目:PHP教程 来源:网络整理
导读:我的本地主机上有一个页面,用户可以从该页面上传视频.现在我想实现这个功能,管理员可以将这些视频公开(用户必须将其作为私人视频上传). 现在,首先我需要获得频道上所有视频的列表(包括私有视频).我试过这段代码: $data = '?xml version="1.0"? entry xmlns=
我的本地主机上有一个页面,用户可以从该页面上传视频.现在我想实现这个功能,管理员可以将这些视频公开(用户必须将其作为私人视频上传).
现在,首先我需要获得频道上所有视频的列表(包括私有视频).我试过这段代码: $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,CURLOPT_HTTPHEADER,$headers ); curl_setopt( $curl,CURLOPT_POSTFIELDS,$data ); curl_setopt( $curl,CURLOPT_REFERER,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:.... 我无法找到用于请求用户视频列表的正确形式的标题,因此我使用了我申请上传视频的标题(并且哪些有效,因此我确信用户身份验证没有问题). 如果你能告诉我我做错了什么,或者只是给我一个工作视频列表的例子,我将非常感激. 编辑: 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(版本> = 1.7.7)扩展名的Zend库解决了这个问题.还要注意PHP版本必须是> = 5.1.4.
参考:Google YouTube API – PHP (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |