Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3720

Using an API key Why can I max retrieve 20k videos? Also why only public videos?

$
0
0

OnYouTube API to fetch all videos on a channel

found compact sample PHP under heading "Here is the code that will return all video ids under your channel".

Program shown below.

I expanded the program to fetch various attributes of each video, including ACCESS.

I have a channel with over 20,000 videos and large quote.

The program ran nicely and produced a .csv with video attributes.

It ran for about 2 hours and 10 minutes and stopped at 20,000 videos. In addition it only picked up PUBLIC videos.

How can the above two issues be remedied?

<?php // FROM https://stackoverflow.com/questions/18953499/youtube-api-to-fetch-all-videos-on-a-channel/70071113#70071113    $baseUrl = 'https://www.googleapis.com/youtube/v3/';    // https://developers.google.com/youtube/v3/getting-started    $apiKey = 'API_KEY';    // If you don't know the channel ID see below    $channelId = 'CHANNEL_ID';    $params = ['id'=> $channelId,'part'=> 'contentDetails','key'=> $apiKey    ];    $url = $baseUrl . 'channels?' . http_build_query($params);    $json = json_decode(file_get_contents($url), true);    $playlist = $json['items'][0]['contentDetails']['relatedPlaylists']['uploads'];    $params = ['part'=> 'snippet','playlistId' => $playlist,'maxResults'=> '50','key'=> $apiKey    ];    $url = $baseUrl . 'playlistItems?' . http_build_query($params);    $json = json_decode(file_get_contents($url), true);    $videos = [];    foreach($json['items'] as $video)        $videos[] = $video['snippet']['resourceId']['videoId'];    while(isset($json['nextPageToken'])){        $nextUrl = $url . '&pageToken=' . $json['nextPageToken'];        $json = json_decode(file_get_contents($nextUrl), true);        foreach($json['items'] as $video)            $videos[] = $video['snippet']['resourceId']['videoId'];    }    print_r($videos);?>

Viewing all articles
Browse latest Browse all 3720

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>