php - 如何使用 php 在网站上嵌入 youtube channel 视频

标签 php iframe youtube embed channel

youtube api v3 更新后,我不知道如何修复我网站的视频部分。
该部分显示在我的 youtube channel UCBL3ecWukz_EX7FrDmtdgJQ 上传的视频

我已经创建了 OAuth:Web 应用程序的客户端 ID,公共(public) API 访问:服务器应用程序的 key 和浏览器应用程序的 key 。

现在我正在尝试了解如何使用它们来检索上传到我的 channel 的视频列表。

我试过这段代码

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCBL3ecWukz_EX7FrDmtdgJQ&maxResults=20&key=***************************************

现在我不知道如何处理输出..
类似的东西

{
 "kind": "youtube#searchListResponse",
 "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/6M9Lo8BzT3ingng1jJF2bBh1CNs\"",
 "pageInfo": {
  "totalResults": 5,
  "resultsPerPage": 20
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/LHUK9eLdq9H2-Szizgc5BvV-gxM\"",
   "id": {
    "kind": "youtube#channel",
    "channelId": "UCBL3ecWukz_EX7FrDmtdgJQ"
   },
   "snippet": {
    "publishedAt": "2014-12-26T11:20:46.000Z",
    "channelId": "UCBL3ecWukz_EX7FrDmtdgJQ",
    "title": "Parrocchia Sant'Agata Alì",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://lh5.googleusercontent.com/-O78yDecTsmk/AAAAAAAAAAI/AAAAAAAAAAA/U-NQ4NkzZQE/photo.jpg"
     },
     "medium": {
      "url": "https://lh5.googleusercontent.com/-O78yDecTsmk/AAAAAAAAAAI/AAAAAAAAAAA/U-NQ4NkzZQE/photo.jpg"
     },
     "high": {
      "url": "https://lh5.googleusercontent.com/-O78yDecTsmk/AAAAAAAAAAI/AAAAAAAAAAA/U-NQ4NkzZQE/photo.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/YPX-4TZwL2BMwOoIP3pO2_KBzvs\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "FjGA6cjh5zI"
   },
   "snippet": {
    "publishedAt": "2015-02-12T23:45:39.000Z",
    "channelId": "UCBL3ecWukz_EX7FrDmtdgJQ",
    "title": "Alì S  Agata Bacio del braccio",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/FjGA6cjh5zI/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/FjGA6cjh5zI/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/FjGA6cjh5zI/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/-m38lEymXlK8ZVMm2dNRzX8e8ro\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "7PQBjOedbtk"
   },
   "snippet": {
    "publishedAt": "2015-02-07T20:43:40.000Z",
    "channelId": "UCBL3ecWukz_EX7FrDmtdgJQ",
    "title": "Annuncio Festa Grande",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/7PQBjOedbtk/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/7PQBjOedbtk/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/7PQBjOedbtk/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/Bv1fyl1c4aVHIrWuOV5gNf7xpMI\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "Gmelq3hGEPI"
   },
   "snippet": {
    "publishedAt": "2015-02-15T23:17:22.000Z",
    "channelId": "UCBL3ecWukz_EX7FrDmtdgJQ",
    "title": "Alì S  Agata riposta sull'altare",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/Gmelq3hGEPI/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/Gmelq3hGEPI/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/Gmelq3hGEPI/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/LZFjbm4TuWdxvls0Jzan6H6Ow5A\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "GMizgWpyt2k"
   },
   "snippet": {
    "publishedAt": "2015-03-27T22:13:32.000Z",
    "channelId": "UCBL3ecWukz_EX7FrDmtdgJQ",
    "title": "Alì Chiesa S  Agata Preghiera per devozione Padre Serafino",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/GMizgWpyt2k/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/GMizgWpyt2k/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/GMizgWpyt2k/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  }
 ]
}


有人可以解释一下吗
真的很谢谢你!!
附言。对不起第二个巨大的代码报价

最佳答案

真是巧合...几天前我才需要这个:)这是我使用的代码:

<?php
    $playlistID = ''; // The Playlist ID for your 'uploads'-playlist.
    $videofile = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=10&playlistId=' . $playlistID;
    $json = file_get_contents($videofile);
    $json = preg_replace('/^\xEF\xBB\xBF/', '', $json);
    $array = json_decode($json, TRUE);

    foreach ($array as $key => $value) {
        if ($key == "items") {
            echo "<table class='vtable'>";
            for ($i = 0; $i < count($array["items"]); $i = $i + 1) {
                $id = $array["items"][$i]['snippet']['resourceId']['videoId'];
                $thumbnail = $array["items"][$i]['snippet']['thumbnails']['high']['url'];
                $title = $array["items"][$i]['snippet']['title'];
                $description = $array["items"][$i]['snippet']['description'];
                // do some stuff with the variables
            }
        }
    }
?>

关于php - 如何使用 php 在网站上嵌入 youtube channel 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31629037/

相关文章:

c# - 我可以使用 Visual Studio 的数据源配置向导连接到 YouTube api 吗?

php - 将数组传递给 CakePHP 中的 requestAction

php - 避免从 select 语句中显示重复值

c# - 从背后的 ASP.NET 代码与 iFrame 对话

javascript - 如何检测用户从外部窗口在 iframe 中导航到的 URL?

jquery - 从我的页面中删除嵌入的YouTube

php - 服务器端代码与客户端代码混合 - 最佳实践

php - PHP 中全局错误处理的最佳实践?

youtube - 如何删除我的 YouTube 视频上的垃圾评论并阻止垃圾 channel 评论我的视频?

javascript - YouTube - 如何只播放没有音频的视频?