Using the YouTube API v3 to list all private video

2019-04-14 06:02发布

问题:

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