Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $baseUrl = 'https://www.googleapis.com/youtube/v3/';
- // https://developers.google.com/youtube/v3/getting-started
- $apiKey = 'AIzaSyBE6bAZIR6qa8aMTtvNKc63n0Y-Lk2uMQY';
- // ัhannel ID
- $channelId = 'UCo0FEARvGCNl1e4u0jRBirw';
- $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);?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement