PHP code example of rajagonda / gondayoutube

1. Go to this page and download the library: Download rajagonda/gondayoutube 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/ */

    

rajagonda / gondayoutube example snippets


// use Rajagonda\GondaYoutube\Facades\GondaYoutube;


// Return an STD PHP object
$video = GondaYoutube::getVideoInfo('rie-hPVJ7Sw');

// Get multiple videos info from an array
$videoList = GondaYoutube::getVideoInfo(['rie-hPVJ7Sw','iKHTawgyKWQ']);

// Get multiple videos related to a video
$relatedVideos = GondaYoutube::getRelatedVideos('iKHTawgyKWQ');

// Get comment threads by videoId
$commentThreads = GondaYoutube::getCommentThreadsByVideoId('zwiUB_Lh3iA');

// Get popular videos in a country, return an array of PHP objects
$videoList = GondaYoutube::getPopularVideos('us');

// Search playlists, channels and videos. return an array of PHP objects
$results = GondaYoutube::search('Android');

// Only search videos, return an array of PHP objects
$videoList = GondaYoutube::searchVideos('Android');

// Search only videos in a given channel, return an array of PHP objects
$videoList = GondaYoutube::searchChannelVideos('keyword', 'UCk1SpWNzOs4MYmr0uICEntg', 40);

// List videos in a given channel, return an array of PHP objects
$videoList = GondaYoutube::listChannelVideos('UCk1SpWNzOs4MYmr0uICEntg', 40);

$results = GondaYoutube::searchAdvanced([ /* params */ ]);

// Get channel data by channel name, return an STD PHP object
$channel = GondaYoutube::getChannelByName('xdadevelopers');

// Get channel data by channel ID, return an STD PHP object
$channel = GondaYoutube::getChannelById('UCk1SpWNzOs4MYmr0uICEntg');

// Get playlist by ID, return an STD PHP object
$playlist = GondaYoutube::getPlaylistById('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs');

// Get playlists by multiple ID's, return an array of STD PHP objects
$playlists = GondaYoutube::getPlaylistById(['PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs', 'PL590L5WQmH8cUsRyHkk1cPGxW0j5kmhm0']);

// Get playlist by channel ID, return an array of PHP objects
$playlists = GondaYoutube::getPlaylistsByChannelId('UCk1SpWNzOs4MYmr0uICEntg');

// Get items in a playlist by playlist ID, return an array of PHP objects
$playlistItems = GondaYoutube::getPlaylistItemsByPlaylistId('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs');

// Get channel activities by channel ID, return an array of PHP objects
$activities = GondaYoutube::getActivitiesByChannelId('UCk1SpWNzOs4MYmr0uICEntg');

// Retrieve video ID from original YouTube URL
$videoId = GondaYoutube::parseVidFromURL('https://www.youtube.com/watch?v=moSFlvxnbgk');
// result: moSFlvxnbgk

// Set default parameters
$params = [
    'q'             => 'Android',
    'type'          => 'video',
    'part'          => 'id, snippet',
    'maxResults'    => 50
];

// Make intial call. with second argument to reveal page info such as page tokens
$search = GondaYoutube::searchAdvanced($params, true);

// Check if we have a pageToken
if (isset($search['info']['nextPageToken'])) {
    $params['pageToken'] = $search['info']['nextPageToken'];
}

// Make another call and repeat
$search = GondaYoutube::searchAdvanced($params, true);

// Add results key with info parameter set
print_r($search['results']);

/* Alternative approach with new built-in paginateResults function */

// Same params as before
$params = [
    'q'             => 'Android',
    'type'          => 'video',
    'part'          => 'id, snippet',
    'maxResults'    => 50
];

// An array to store page tokens so we can go back and forth
$pageTokens = [];

// Make inital search
$search = GondaYoutube::paginateResults($params, null);

// Store token
$pageTokens[] = $search['info']['nextPageToken'];

// Go to next page in result
$search = GondaYoutube::paginateResults($params, $pageTokens[0]);

// Store token
$pageTokens[] = $search['info']['nextPageToken'];

// Go to next page in result
$search = GondaYoutube::paginateResults($params, $pageTokens[1]);

// Store token
$pageTokens[] = $search['info']['nextPageToken'];

// Go back a page
$search = GondaYoutube::paginateResults($params, $pageTokens[0]);

// Add results key with info parameter set
print_r($search['results']);

$ php artisan vendor:publish --provider="Rajagonda\GondaYoutube\GondaYoutubeServiceProvider"

/config/gondayoutube.php