PHPackages                             marcusyan/youtube - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. marcusyan/youtube

ActiveLibrary[API Development](/categories/api)

marcusyan/youtube
=================

Laravel PHP Facade/Wrapper for the Youtube Data API v3

2.2.2(6y ago)01.0kPHPPHP ^7.0

Since Dec 3Pushed 2y agoCompare

[ Source](https://github.com/Marcusyan/Youtube)[ Packagist](https://packagist.org/packages/marcusyan/youtube)[ RSS](/packages/marcusyan-youtube/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (15)Used By (0)

Youtube
=======

[](#youtube)

[![Travis Youtube Build](https://camo.githubusercontent.com/76d9121ecfdc790c8df4582c06d80b5ddaca0310392008083eaa3109550453c0/68747470733a2f2f6170692e7472617669732d63692e6f72672f616c616f75792f596f75747562652e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/76d9121ecfdc790c8df4582c06d80b5ddaca0310392008083eaa3109550453c0/68747470733a2f2f6170692e7472617669732d63692e6f72672f616c616f75792f596f75747562652e7376673f6272616e63683d6d6173746572) [![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.me/alaouym)

Laravel PHP Facade/Wrapper for the Youtube Data API v3 ( Non-OAuth )

Requirements
------------

[](#requirements)

- PHP 7.0 or higher
- Laravel 5.1 or higher
- API key from [Google Console](https://console.developers.google.com)

Looking for Youtube Package for either of these: PHP 5, Laravel 5.0, Laravel 4? Visit the [`php5-branch`](https://github.com/alaouy/Youtube/tree/php5)

Installation
------------

[](#installation)

Run in console below command to download package to your project:

```
composer require alaouy/youtube

```

Configuration
-------------

[](#configuration)

In `/config/app.php` add YoutubeServiceProvider:

```
Alaouy\Youtube\YoutubeServiceProvider::class,

```

Do not forget to add also Youtube facade there:

```
'Youtube' => Alaouy\Youtube\Facades\Youtube::class,

```

Publish config settings:

```
$ php artisan vendor:publish --provider="Alaouy\Youtube\YoutubeServiceProvider"

```

Set your Youtube API key in the file:

```
/config/youtube.php

```

Or in the .env file

```
YOUTUBE_API_KEY = KEY

```

Or you can set the key programmatically at run time :

```
Youtube::setApiKey('KEY');

```

Usage
-----

[](#usage)

```
// use Alaouy\Youtube\Facades\Youtube;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Basic Search Pagination
-----------------------

[](#basic-search-pagination)

```
// 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 = Youtube::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 = Youtube::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 = Youtube::paginateResults($params, null);

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

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

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

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

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

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

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

The pagination above is quite basic. Depending on what you are trying to achieve you may want to create a recursive function that traverses the results.

Run Unit Test
-------------

[](#run-unit-test)

If you have PHPUnit installed in your environment, run:

```
$ phpunit
```

If you don't have PHPUnit installed, you can run the following:

```
$ composer update
$ ./vendor/bin/phpunit
```

Format of returned data
-----------------------

[](#format-of-returned-data)

The returned JSON is decoded as PHP objects (not Array). Please read the ["Reference" section](https://developers.google.com/youtube/v3/docs/) of the Official API doc.

Youtube Data API v3
-------------------

[](#youtube-data-api-v3)

- [Youtube Data API v3 Doc](https://developers.google.com/youtube/v3/)
- [Obtain API key from Google API Console](https://console.developers.google.com)

Donation
--------

[](#donation)

If you find this project to be of use to you please consider buying me a cup of tea :)

[![paypal](https://camo.githubusercontent.com/e1ff554a09e8e92bef25abc553ff05b88f45afd695877cf12f3a46558ef65b2e/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e61746543435f4c472e676966)](https://www.paypal.me/alaouym)

Credits
-------

[](#credits)

Built on code from Madcoda's [php-youtube-api](https://github.com/madcoda/php-youtube-api).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 59.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~150 days

Recently: every ~212 days

Total

13

Last Release

2374d ago

Major Versions

v1.2.4 → v2.02017-07-12

v1.2.5 → v2.1.02017-07-14

PHP version history (2 changes)v1.0PHP &gt;=5.3.0

v2.0PHP ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8740410?v=4)[marcusyan](/maintainers/Marcusyan)[@Marcusyan](https://github.com/Marcusyan)

---

Top Contributors

[![alaouy](https://avatars.githubusercontent.com/u/3118889?v=4)](https://github.com/alaouy "alaouy (73 commits)")[![bzbislawski](https://avatars.githubusercontent.com/u/12448772?v=4)](https://github.com/bzbislawski "bzbislawski (11 commits)")[![mahmutbayri](https://avatars.githubusercontent.com/u/1398166?v=4)](https://github.com/mahmutbayri "mahmutbayri (8 commits)")[![vishal-sancheti](https://avatars.githubusercontent.com/u/4789936?v=4)](https://github.com/vishal-sancheti "vishal-sancheti (4 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (4 commits)")[![digitalhuman](https://avatars.githubusercontent.com/u/780848?v=4)](https://github.com/digitalhuman "digitalhuman (3 commits)")[![akiyamaSM](https://avatars.githubusercontent.com/u/12276076?v=4)](https://github.com/akiyamaSM "akiyamaSM (2 commits)")[![Marcusyan](https://avatars.githubusercontent.com/u/8740410?v=4)](https://github.com/Marcusyan "Marcusyan (2 commits)")[![qWici](https://avatars.githubusercontent.com/u/11472929?v=4)](https://github.com/qWici "qWici (2 commits)")[![Rpsl](https://avatars.githubusercontent.com/u/265634?v=4)](https://github.com/Rpsl "Rpsl (2 commits)")[![kleiberd](https://avatars.githubusercontent.com/u/5521697?v=4)](https://github.com/kleiberd "kleiberd (1 commits)")[![lamoni](https://avatars.githubusercontent.com/u/5675626?v=4)](https://github.com/lamoni "lamoni (1 commits)")[![lucaspanik](https://avatars.githubusercontent.com/u/7035554?v=4)](https://github.com/lucaspanik "lucaspanik (1 commits)")[![jesusvazquez](https://avatars.githubusercontent.com/u/2439858?v=4)](https://github.com/jesusvazquez "jesusvazquez (1 commits)")[![dwaxweiler](https://avatars.githubusercontent.com/u/12501775?v=4)](https://github.com/dwaxweiler "dwaxweiler (1 commits)")[![messerli90](https://avatars.githubusercontent.com/u/3306651?v=4)](https://github.com/messerli90 "messerli90 (1 commits)")[![paoloposo](https://avatars.githubusercontent.com/u/10469413?v=4)](https://github.com/paoloposo "paoloposo (1 commits)")[![tylergets](https://avatars.githubusercontent.com/u/9418094?v=4)](https://github.com/tylergets "tylergets (1 commits)")[![bryant1410](https://avatars.githubusercontent.com/u/3905501?v=4)](https://github.com/bryant1410 "bryant1410 (1 commits)")[![joaoeaugusto](https://avatars.githubusercontent.com/u/2657999?v=4)](https://github.com/joaoeaugusto "joaoeaugusto (1 commits)")

---

Tags

apilaravelvideoyoutubealaouy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marcusyan-youtube/health.svg)

```
[![Health](https://phpackages.com/badges/marcusyan-youtube/health.svg)](https://phpackages.com/packages/marcusyan-youtube)
```

###  Alternatives

[alaouy/youtube

Laravel PHP Facade/Wrapper for the Youtube Data API v3

8091.3M9](/packages/alaouy-youtube)[madcoda/php-youtube-api

PHP wrapper for the Youtube Data API v3

4451.2M8](/packages/madcoda-php-youtube-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
