Using the YouTube API v3 to list all private videos

孤者浪人 提交于 2019-12-09 19:26:01

问题


Currently I'm building a site that will use a small number of user uploaded videos. These videos are uploaded to the server, then moved on to YouTube via the API v3. The private tag is set, and all videos are uploaded into one central account.

My problem is; how can I access and list all these private videos via the API to display on my site? I'm not sure if this is possible. Any feed back would be much appreciated.

After looking into it more I found this. After looking through the docs I couldn't find a PHP specific example of how I could do this: getuserUploads.


回答1:


  1. Get the ZF Gdata Library @ http://framework.zend.com/downloads/latest

  2. Run the Autoloader:

    set_include_path(APPPATH . 'third_party/zf/' . get_include_path());
    require 'Zend/Loader/Autoloader.php';
    Zend_Loader_Autoloader::getInstance();
    
  3. Create an HTTP Instance with your youtube Login, Password, and Developer Key (Youll have to grab one).

       $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
                "Youtube LOGIN", 
                "Youtube PASSWORD", 
                'youtube'
        );
    
  4. Instantiate GData with your cedentials

        $yt = new Zend_Gdata_YouTube(
                $httpClient, 
                null,
                null, 
                "Youtube Developer Key"
        );
    
  5. Fetch your playlist

        $playlistListFeed = $yt->getPlaylistListFeed("YOUR YOUTUBE CHANNEL NAME");
        //print_r($playlistListFeed); // uncomment to see the goods
    
  6. Prepare an array to sort through less data

        $data['feed'] = array();
    
  7. Loop through everything, use the is_private to tell if its private or not

        foreach ($playlistListFeed as $playlistEntry) 
        {
          $feedUrl = $playlistEntry->getPlaylistVideoFeedUrl();
          $playlistVideoFeed = $yt->getPlaylistVideoFeed($feedUrl);
    
          foreach ($playlistVideoFeed as $video) {
    
            $data['feed'][] = array(
                'id' => $video->getVideoId(),
                'title' => $video->getTitle(),
                'thumbnail' => $video->getVideoThumbnails(),
                'is_private' => $video->isVideoPrivate(),
                'url' => $video->getVideoWatchPageUrl(),
                'flash_url' => $video->getFlashPlayerUrl ()
            );
        }
    
    } 
    

You may have to tinker around with it to get it right to your settings, hope this helps.




回答2:


I believe that you can do that, using the YouTube Data v3, in this way:

Get the uploaded videos in this way (it is a Java example):

https://developers.google.com/youtube/v3/docs/playlistItems/list#examples

And then you can retrieve the videos resources for these playlistitems using:

https://developers.google.com/youtube/v3/docs/videos/list

And then you can verify the status.privacyStatus in each video resource (if you upload videos with a different status.privacyStatus .. )



来源:https://stackoverflow.com/questions/14612000/using-the-youtube-api-v3-to-list-all-private-videos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!