PHP code example of incremental / php-youtube
1. Go to this page and download the library: Download incremental/php-youtube library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
incremental / php-youtube example snippets
ncremental\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=
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/
ncremental\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
* )
* )
* )
*/