Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?
  2. $baseUrl = 'https://www.googleapis.com/youtube/v3/';
  3. // https://developers.google.com/youtube/v3/getting-started
  4. $apiKey = 'AIzaSyBE6bAZIR6qa8aMTtvNKc63n0Y-Lk2uMQY';
  5. // ัhannel ID
  6. $channelId = 'UCo0FEARvGCNl1e4u0jRBirw';
  7.  
  8. $params = [
  9. 'id'=> $channelId,
  10. 'part'=> 'contentDetails',
  11. 'key'=> $apiKey
  12. ];
  13. $url = $baseUrl . 'channels?' . http_build_query($params);
  14. $json = json_decode(file_get_contents($url), true);
  15.  
  16. $playlist = $json['items'][0]['contentDetails']['relatedPlaylists']['uploads'];
  17.  
  18. $params = [
  19. 'part'=> 'snippet',
  20. 'playlistId' => $playlist,
  21. 'maxResults'=> '50',
  22. 'key'=> $apiKey
  23. ];
  24. $url = $baseUrl . 'playlistItems?' . http_build_query($params);
  25. $json = json_decode(file_get_contents($url), true);
  26.  
  27. $videos = [];
  28. foreach($json['items'] as $video)
  29. $videos[] = $video['snippet']['resourceId']['videoId'];
  30.  
  31. while(isset($json['nextPageToken'])){
  32. $nextUrl = $url . '&pageToken=' . $json['nextPageToken'];
  33. $json = json_decode(file_get_contents($nextUrl), true);
  34. foreach($json['items'] as $video)
  35. $videos[] = $video['snippet']['resourceId']['videoId'];
  36. }
  37. print_r($videos);?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement