4

ユーザーがビデオをアップロードできるページをローカルホストに持っています。ここで、管理者がこれらの動画を公開できる機能を実装したいと思います (ユーザーは非公開動画としてアップロードする必要があります)。そのためには、まずチャンネルのすべての動画 (非公開動画を含む) のリストを取得する必要があります。私はこのコードを試しました:

    $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 はこれを返します:

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)
4

2 に答える 2

1

上記のコメントを参照して、Zend_Gdata (バージョン >= 1.7.7) 拡張子を持つ Zend ライブラリをインストールすると、問題が解決しました。また、PHP のバージョンは >= 5.1.4 である必要があることにも注意してください。

参考:Google YouTube API - PHP

于 2012-12-28T02:29:20.507 に答える