incremental/php-youtube

一个简单的YouTube API封装库。

1.0.0 2015-07-09 18:19 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:54:39 UTC


README

Build Status

PHP-YouTube

该库旨在提供一个易于使用的封装,用于非OAuth YouTube API (v3) 端点。

支持的操作

youtube.activities.list

返回与给定频道ID匹配的频道活动事件列表。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/activities/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listActivities([
    'part'       => 'id',
    'channelId'  => 'UCVHFbqXqoYvEWM1Ddxl0QDg',
    'maxResults' => 1
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#activityListResponse
 *     [etag] => "eYE31WLho912TfxEBDDRSwEQ5Ms/LZ35K6cHrk3gvAbMl22qG9gJzlk"
 *     [nextPageToken] => CAEQAA
 *     [pageInfo] => Array
 *         (
 *             [totalResults] => 9
 *             [resultsPerPage] => 1
 *         )
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#activity
 *                     [etag] => "eYE31WLho912TfxEBDDRSwEQ5Ms/WcC5XzEdaxXmLhsuZ1s9_CBqix8"
 *                     [id] => VTE0MzQwNDMxMDYxNDAxNDY3MTQzNjM5MjA=
 *                 )
 *         )
 * )
 */

youtube.channels.list

返回符合请求条件的零个或多个频道资源。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/channels/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listChannels([
    'part'       => 'id',
    'channelId'  => 'GCQmVzdCBvZiBZb3VUdWJl',
    'maxResults' => 1
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#channelListResponse
 *     [etag] => "eYE31WLho912TfxEBDDRSwEQ5Ms/vScTfQD3jJn-MzW5d9kDHIJU61w"
 *     [nextPageToken] => CAEQAA
 *     [pageInfo] => Array
 *         (
 *             [totalResults] => 11
 *             [resultsPerPage] => 1
 *         )
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#channel
 *                     [etag] => "eYE31WLho912TfxEBDDRSwEQ5Ms/sgkeX05nlECWsuF-d1WorqhxJVQ"
 *                     [id] => UCF0pVplsI8R5kcAqgtoRqoA
 *                 )
 *         )
 * )
 */

youtube.channelsections.list

返回符合请求条件的频道部分资源列表。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/channelSections/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listChannelSections([
    'part'       => 'id',
    'channelId'  => 'GCQmVzdCBvZiBZb3VUdWJl',
]);

print_r($response);

/**
 * Array
 * (
 *    [kind] => youtube#channelSectionListResponse
 *    [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/4JnIcJTNhW-8qjW5Xh2gRXpVNh8"
 *    [items] => Array
 *        (
 *            [0] => Array
 *                (
 *                    [kind] => youtube#channelSection
 *                    [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/Yf2NnAr2mk7seya0WwQIJgvb5H4"
 *                    [id] => UCVHFbqXqoYvEWM1Ddxl0QDg.__WLXNpu6u8
 *                    [snippet] => Array
 *                        (
 *                            [type] => singlePlaylist
 *                            [style] => horizontalRow
 *                            [channelId] => UCVHFbqXqoYvEWM1Ddxl0QDg
 *                            [position] => 0
 *                        )
 *                )
 *         )
 * )
 */

youtube.comments.list

返回符合请求条件的评论列表。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/comments/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listComments([
    'part'       => 'id',
    'channelId'  => 'z131gtcqbqbft5y3x22jfvmoakf3ezfsi',
    'maxResults' => 1,
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#commentListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/my2z1KHSZNVuD41bSHIrxgS8G-U"
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#comment
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/4Lac9A_R38HxodU7PaftM_J1BaY"
 *                     [id] => z131gtcqbqbft5y3x22jfvmoakf3ezfsi
 *                 )
 *         )
 * )
 */

youtube.commentthreads.list

返回符合请求条件的评论线程列表。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/commentThreads/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listCommentThreads([
    'part'       => 'id',
    'videoId'    => 'z131gtcqbqbft5y3x22jfvmoakf3ezfsi',
    'maxResults' => 1,
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#commentThreadListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/uN-iOCehYpos4TNPM5gjN8UB1xY"
 *     [nextPageToken] => Cg0Qr9vwvY3AxgIgACgBEhQIABDIrYirubDGAhjIrYirubDGAhgCIAE=
 *     [pageInfo] => Array
 *         (
 *             [resultsPerPage] => 1
 *         )
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#commentThread
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/7sgGL5ZZoBDiABrwCZQ4HWh7TPs"
 *                     [id] => z12lxfwxtzqwhdfrq04cgnqowyusftk4esk0k
 *                 )
 *         )
 * )
 */

youtube.guidecategories.list

返回可以与YouTube频道关联的类别列表。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/guideCategories/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listGuideCategories([
    'part'       => 'id',
    'regionCode' => 'NL',
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#guideCategoryListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/MnjXoNFdOgOUSRqlgJ3cE1jYWvg"
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#guideCategory
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/ei31gUqEQxOtnflo47cy0YAa_MM"
 *                     [id] => GCQmVzdCBvZiBZb3VUdWJl
 *                 )
 *         )
 * )
 */

youtube.i18nLanguages.list

返回YouTube网站支持的应用程序语言列表。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/i18nLanguages/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listI18nLanguages([
    'part'       => 'id',
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#i18nLanguageListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/wD1Vj4GH0IYKZJOUyuxIoquCcHs"
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#i18nLanguage
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/8KwAGX0iEJffc-VyQgBD2mnlbac"
 *                     [id] => af
 *                 )
 *         )
 * )
 */

youtube.i18nRegions.list

返回YouTube网站支持的内容区域列表。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/i18nRegions/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listI18nRegions([
    'part'       => 'id',
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#i18nRegionListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/z8_sDbXXqFQ0QvdJ-9cH9JGf4o4"
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#i18nRegion
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/1K5qc4QfRqfgcFVQseK1hTW9b2c"
 *                     [id] => US
 *                 )
 *         )
 * )
 */

youtube.playlistItems.list

返回与API请求参数匹配的播放列表项集合。您可以从指定的播放列表中检索所有播放列表项,或者通过其唯一的ID检索一个或多个播放列表项。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/playlistItems/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listPlaylistItems([
    'part'          => 'id',
    'playlistId'    => 'PLWz5rJ2EKKc9ofd2f-_-xmUi07wIGZa1c',
    'maxResults'    => 1,
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#playlistItemListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/hBziD0I-EcwiXydv0GDIrIg_tms"
 *     [nextPageToken] => CAEQAA
 *     [pageInfo] => Array
 *         (
 *             [totalResults] => 24
 *             [resultsPerPage] => 1
 *         )
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#playlistItem
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/I3VVE1hQi9lf5TYMwq0PobNjGqo"
 *                     [id] => PLqKOsfcZLLdlAo54wkuLqIjRo-SaPCQYyZicRPdwWWRg
 *                 )
 *         )
 * )
 */

youtube.playlists.list

返回与API请求参数匹配的播放列表集合。例如,您可以通过其唯一的ID检索一个或多个播放列表。

有关更多信息,请参阅 https://developers.google.com/youtube/v3/docs/playlists/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listPlaylists([
    'part'          => 'id',
    'playlistId'    => 'PLWz5rJ2EKKc9ofd2f-_-xmUi07wIGZa1c',
    'maxResults'    => 1,
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#playlistListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/rj5IqmLz71fFu6p4mMXlJmpJfxM"
 *     [nextPageToken] => CAEQAA
 *     [pageInfo] => Array
 *         (
 *             [totalResults] => 55
 *             [resultsPerPage] => 1
 *         )
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#playlist
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/ZF8lhREd15KN22t7926-2iNFGd0"
 *                     [id] => PLWz5rJ2EKKc-rru_xVZNamRDaQfHr6ebv
 *                 )
 *         )
 * )
 */

youtube.search.list

返回与API请求中指定的查询参数匹配的搜索结果集合。默认情况下,搜索结果集标识匹配视频、频道和播放列表资源,但您也可以配置查询仅检索特定类型的资源。

了解更多信息,请参阅 https://developers.google.com/youtube/v3/docs/search/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listSearch([
    'part'          => 'id',
    'channelId'     => 'UC_x5XG1OV2P6uZZ5FSM9Ttw',
    'maxResults'    => 1,
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#searchListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/G4Uurrtcf18axqH_LSyFmuhf2X4"
 *     [nextPageToken] => CAEQAA
 *     [pageInfo] => Array
 *         (
 *             [totalResults] => 3988
 *             [resultsPerPage] => 1
 *         )
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#searchResult
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/q4hYefapiMoagc7b_3bYaVZvSJo"
 *                     [id] => Array
 *                         (
 *                             [kind] => youtube#channel
 *                             [channelId] => UC_x5XG1OV2P6uZZ5FSM9Ttw
 *                         )
 *                 )
 *         )
 * )
 */

youtube.subscriptions.list

返回符合API请求标准的订阅资源。

了解更多信息,请参阅 https://developers.google.com/youtube/v3/docs/subscriptions/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listSubscriptions([
    'part'          => 'id',
    'channelId'     => 'UC_x5XG1OV2P6uZZ5FSM9Ttw',
    'maxResults'    => 1,
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#subscriptionListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/Tjfg1JrIT4dfOWI4p2GAh62RkuM"
 *     [nextPageToken] => CAEQAA
 *     [pageInfo] => Array
 *         (
 *             [totalResults] => 44
 *             [resultsPerPage] => 1
 *         )
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#subscription
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/AMk7GKpqy6n7dqRBhb9OkS9yCrg"
 *                     [id] => MpajmvGNexIkHC8F7y2fiZ-2BKHlv54sys7NqgqY_ak
 *                 )
 *         )
 * )
 */

youtube.videocategories.list

返回可以与YouTube视频相关联的分类列表。

了解更多信息,请参阅 https://developers.google.com/youtube/v3/docs/videoCategories/list

<?php

require_once('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listVideoCategories([
    'part'          => 'id',
    'regionCode'    => 'NL',
]);

print_r($response);

/**
 * Array
 * (
 *     [kind] => youtube#videoCategoryListResponse
 *     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/d2nxEqpmtIzd-HWoYLbxZeG5Ig8"
 *     [items] => Array
 *         (
 *             [0] => Array
 *                 (
 *                     [kind] => youtube#videoCategory
 *                     [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/XLk_qpc4aA4EW__lDxBJzY9kMIg"
 *                     [id] => 1
 *                 )
 *         )
 * )
 */

youtube.videos.list

返回符合API请求参数的视频列表。

了解更多信息,请参阅 https://developers.google.com/youtube/v3/docs/videos/list

<?php

require_once ('vendor/autoload.php');

use Incremental\YouTube\YouTube;

$youtube = new YouTube('YOUR_API_KEY');
$response = $youtube->listVideos([
    'part'          => 'id',
    'chart'         => 'mostPopular',
    'maxResults'    => 1,
]);

print_r($response);

/**
 * Array
 * (
 *    [kind] => youtube#videoListResponse
 *    [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/5vKizhjk_5NDC69NYkSsP90NfQ4"
 *    [nextPageToken] => CAUQAA
 *    [pageInfo] => Array
 *        (
 *            [totalResults] => 30
 *            [resultsPerPage] => 1
 *        )
 *
 *    [items] => Array
 *        (
 *            [0] => Array
 *                (
 *                    [kind] => youtube#video
 *                    [etag] => "Y3xTLFF3RLtHXX85JBgzzgp2Enw/D0_V-FNcsvu5O5nb4WVaywcVcNY"
 *                    [id] => PLlMTn_Jzok
 *                )
 *        )
 * )
 */