彰化一整天的論壇

 找回密碼
 立即註冊
查看: 59|回復: 0

HOW TO GET A LIST OF VIDEOS IN YOUTUBE CHANNEL USING PHP & YOUTUBE API

[複製鏈接]
發表於 2018-6-28 14:02:02 | 顯示全部樓層 |閱讀模式

  1. $myApiKey="#########"; // Provide your API Key
  2. $myChannelID="##########"; // Provide your Channel ID
  3. $maxResults="10"; // Number of results to display

  4. // Make an API call to store list of videos to JSON variable
  5. $myQuery = "https://www.googleapis.com/youtube/v3/search?key=$myApiKey&channelId=$myChannelID&part=snippet,id&order=date&maxResults=20";
  6. $videoList = file_get_contents($myQuery);

  7. // Convert JSON to PHP Array
  8. $decoded = json_decode($videoList, true);

  9. // Run a loop to display list of videos
  10. foreach ($decoded['items'] as $items)
  11. {
  12. $id = $items['id']['videoId'];
  13. $title= $items['snippet']['title'];
  14. $description = $items['snippet']['description'];
  15. $thumbnail = $items['snippet']['thumbnails']['default']['url'];

  16. // Display list with some basic CSS formatting
  17. echo "
  18. <p style='display:inline-block;width:200px;margin:10px;text-align:center;vertical-align:top'>";
  19. echo "<img src='$thumbnail'>
  20. ";
  21. echo "<strong>$title</strong>
  22. ";
  23. echo "<small>$description</small>";
  24. echo "

  25. ";
  26. }
複製代碼
資料來源: https://aeykaytech.wordpress.com ... ng-php-youtube-api/

回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

 ㄚ母滴雞湯
 員林香純滴雞精

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)  |网站地图

GMT+8, 2018-9-24 23:16 , Processed in 0.114566 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表