2

我目前有一些工作可以根据我的 Youtube 用户名获取我的所有视频。现在我也需要让它拉出我的私人视频。

我需要一切工作的方式是当我将视频上传到 Youtube 时,它​​会自动嵌入我的受密码保护的网页中。

我创建了我的 API 密钥,还使用了 Oauth 2.0 沙盒,并且能够检索所有视频,包括私人视频,但我不知道如何将 Oauth 与我当前的编码集成,如下所示:

    <?php


    // set feed URL
    $feedURL = 'http://gdata.youtube.com/feeds/api/users/tprestinario/uploads';

    // read feed into SimpleXML object
    $sxml = simplexml_load_file($feedURL);
    ?>
      <h1><?php echo $sxml->title; ?></h1>
    <?php
    // iterate over entries in feed
    foreach ($sxml->entry as $entry) {
      // get nodes in media: namespace for media information
      $media = $entry->children('http://search.yahoo.com/mrss/');

      // get video player URL
      $attrs = $media->group->player->attributes();
      $watch = $attrs['url']; 

      // get video thumbnail
      $attrs = $media->group->thumbnail[0]->attributes();
      $thumbnail = $attrs['url']; 


          // get <yt:duration> node for video length 
      $yt = $media->children('http://gdata.youtube.com/schemas/2007'); 
      $attrs = $yt->duration->attributes(); 
      $length = $attrs['seconds']; 
        $videoid = $yt->videoid[0]; 

      ?>

        <div class="item">
            <h1><?php echo $media->group->title; ?></h1>
            <p><?php echo $media->group->description; ?></p>
            <iframe width="560" height="315" src="http://www.youtube.com/embed/<?php echo $videoid; ?>" frameborder="0" allowfullscreen></iframe> 
        </div>      
   <?php
    }
    ?>
4

1 回答 1

0

如果您使用YouTube Data API V3,那会容易得多。

这是这个用例的一个很好的例子。

https://code.google.com/p/youtube-api-samples/source/browse/samples/php/my_uploads.php

于 2013-03-03T15:58:12.693 回答