我目前正在使用youtube api v3。我正在尝试从特定的播放列表中检索video ids。我已经搜索了文档,但找不到引用该示例或类似内容的示例。我正在使用GITHUB的这个仓库。如何从给定的video ids中检索playlist id

这是一个片段,但仅产生播放列表的一般信息:

require 'vendor/autoload.php';

use Madcoda\Youtube;

$youtube = new Youtube(array('key' => '<API KEY>'));

// Return a std PHP object
$playlist = $youtube->getPlaylistById('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs');

echo "<pre>";
print_r($playlist);
echo "</pre>"

最佳答案

是的你可以 !

YouTube API v3和资源playlistItems.list

使用以下参数获取播放列表的视频ID:

part: 'contentDetails'
playlistId: 'PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs'

https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId=PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs&key= {YOUR_API_KEY}

输出 :
 "items": [
  {

   "kind": "youtube#playlistItem",
   "etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/OCpNe6AE7ww8_WCYOw2M6axwxAY\"",
   "id": "PLDWb5NF1kx1qB7HgQ2tJKvLCsn0D34rFYWn3o4SsrJrU",
   "contentDetails": {
    "videoId": "Lv-sY_z8MNs"
   }
  },
  {

   "kind": "youtube#playlistItem",
   "etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/Qvv0GzRVKvhc4LANFBV171hvlJI\"",
   "id": "PLDWb5NF1kx1qB7HgQ2tJKvAZrOtpGhFVaTYQJQCi66rE",
   "contentDetails": {
    "videoId": "xY_MUB8adEQ"
   }
  },
  {

   "kind": "youtube#playlistItem",
   "etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/rRRgwge6ptZxyMRs-RzsvEFU6qs\"",
   "id": "PLDWb5NF1kx1qB7HgQ2tJKvAI1eXgw8QWwXeA8Anwu4VY",
   "contentDetails": {
    "videoId": "xcc9S_ik0v8"
   }
  }
...

然后,您具有播放列表的视频ID

我快速查找了您在帖子中链接到的github,您将看到以下内容:
(/!\我尚未测试此代码/!)
use Madcoda\Youtube;

$youtube = new Youtube(array('key' => '/* Your API key here */'));

// Set Default Parameters
$params = array(
    'part'          => 'contentDetails',
);

$playlistItems = $youtube->getPlaylistItemsByPlaylistId('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs');

print_r($playlistItems);

关于php - 从播放列表ID检索视频ID-YouTube API V3,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26817919/

10-11 22:14