PHPackages                             igbas90/youtube-data-api - 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. igbas90/youtube-data-api

ActiveLibrary[API Development](/categories/api)

igbas90/youtube-data-api
========================

Youtube Data API v3

2.0(5y ago)033[2 PRs](https://github.com/igbas90/YoutubeDataApi/pulls)MITPHPPHP ^7.2

Since Feb 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/igbas90/YoutubeDataApi)[ Packagist](https://packagist.org/packages/igbas90/youtube-data-api)[ RSS](/packages/igbas90-youtube-data-api/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (3)Versions (7)Used By (0)

Youtube Data API
================

[](#youtube-data-api)

Support APIs
------------

[](#support-apis)

- [channels.list](https://developers.google.com/youtube/v3/docs/channels/list)
- [commentsThread.list](https://developers.google.com/youtube/v3/docs/commentThreads/list)
- [subscriptions.list](https://developers.google.com/youtube/v3/docs/subscriptions/list)
- [videos.list](https://developers.google.com/youtube/v3/docs/videos/list)
- [playlistItems.list](https://developers.google.com/youtube/v3/docs/playlistItems/list)
- [videoCategories.list](https://developers.google.com/youtube/v3/docs/videoCategories/list)

Authorization
-------------

[](#authorization)

> **!!! This library not supported OAuth2, only GOOGLE CONSOLE API KEY**

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

[](#installation)

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

```
composer require igbas90/youtube-data-api

```

Usage
-----

[](#usage)

#### Instance

[](#instance)

Using a single shell. **Services are created when they are accessed**

```
use Igbas90\YoutubeDataApi\YoutubeDataApi;
$dataApiClient = new YoutubeDataApi();
$commentsThreadClient = $dataApiClient->commentsThreadList;
```

Create only service

```
use Igbas90\YoutubeDataApi\Services\CommentsThreadList;
$commentsThreadClient = new CommentsThreadList();
```

#### Set params

[](#set-params)

You can set parameters separately for each service

```
/** @var $dataApiClient Igbas90\YoutubeDataApi\YoutubeDataApi */
$dataApiClient->commentsThreadList->setApiKey('you google console api key');

$dataApiClient->subscriptionsList->setVideoId('9L9UQANH5oI');
```

Bulk settings

```
/** @var $dataApiClient Igbas90\YoutubeDataApi\YoutubeDataApi */
$dataApiClient->commentsThreadList->setParams([
    'apiKey' => "you google console api key",
    'params' => [
        'part' => ['part1', 'part2', ...],
        'videoId' => 'string or array',
        ...
    ]
]);
```

Parameters such as **apiKey**, **proxy**, **responseFormatter** can be set to services when creating in the shell for this, set these parameters in the shell. After creating the services, you can change these parameters only through the methods of the service itself

```
use Igbas90\YoutubeDataApi\YoutubeDataApi;

$dataApiClient = new YoutubeDataApi([
    'apiKey' => 'your google console api key',
    'proxy' => 'http://username:password@ip:port',
    'responseFormatter' => new ResponseFormatter()
]);
```

#### Usage proxy

[](#usage-proxy)

To use a proxy server set it to the service

```
use Igbas90\YoutubeDataApi\YoutubeDataApi;
$dataApiClient = new YoutubeDataApi();

//set proxy
$dataApiClient->commentsThreadList->setProxy('http://username:password@ip:port');

//reset proxy
$dataApiClient->commentsThreadList->resetProxy();
```

#### Get result

[](#get-result)

```
/** @var $client Igbas90\YoutubeDataApi\Services\CommentsThreadList */
$response = $client->request();
```

#### Pagination

[](#pagination)

For pagination you can manually set **pageToken**

```
use Igbas90\YoutubeDataApi\YoutubeDataApi;

$client = (new YoutubeDataApi())->commentsThreadList->setParams([...]);

$response = $client->setPageToken('pageToken')->request();
```

The package has built-in support for paging data. An **ITERATOR** is used for this.

**!!!Attention, the client pageToken will be used as the start for the iterator**

```
/** @var $client \Igbas90\YoutubeDataApi\Services\CommentsThreadList*/
$comments = [];
foreach($client->getIterator() as $response) {
    $body = json_decode($response->getBody(), true);
    $comment = array_merge($comments, $body['items']);
}
```

By default, the iterator works with the original service, which is not very convenient for using multiple iterators. To exclude the influence of the iterator on the service, you can set the iterator to work with the service **clone**. To do this, call the **getIterator()** method, with the parameter **true**.

```
/** @var $client \Igbas90\YoutubeDataApi\Services\CommentsThreadList*/
$iterator1 = $client->getIterator(true);
$iterator2 = $client->setVideoId('videoId')->getIterator(true);
$iterator3 = $client->setParams([
    'videoId' => '9L9UQANH5oI',
    'apiKey' => 'google console api key'
])->getIterator(true);
```

#### Response format

[](#response-format)

By default, Psr\\Http\\Message\\ResponseInterface is returned If you need to return a different format, then you can specify an object that implements the **Igbas90\\YoutubeDataApi\\Classes\\ResponseFormatter** interface, which will be used to convert the returned result.

```
use Igbas90\YoutubeDataApi\Classes\ResponseFormatter;
use Psr\Http\Message\ResponseInterface;

/*
 * Create custom response converter
 */
class BodyJsonDecodeFormatter implements ResponseFormatter
{
    public function format(ResponseInterface $response)
    {
        $content = $response->getBody();
        return json_decode($content, true);
    }
}

/** @var $client Igbas90\YoutubeDataApi\Services\CommentsThreadList */
$client->setResponseFormatter(new BodyJsonDecodeFormatter());

//@var $response array
$response = $client->request();
```

TEST
----

[](#test)

forward running the tests you need to set the environment variables in define.php, for this just copy define-example.php into define.php

```
cp define-example.php define.php

```

replace define.php values ​​with your values.

```
define("API_KEY", "google console key");
define("PROXY", "http://username:password@ip:port");
define("CHANNEL_ID", "UCf-b4GSsV5HJysCi6A0Bm6g");
define("PLAYLIST_ID", "UU_x5XG1OV2P6uZZ5FSM9Ttw");
define("VIDEO_ID", "oxQ7wfiS4GY");
```

Documentations
--------------

[](#documentations)

- [Youtube Data API v3 Doc](https://developers.google.com/youtube/v3/getting-started)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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 ~84 days

Total

4

Last Release

2037d ago

Major Versions

v1.0.2 → 2.02020-10-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/129c4c687303a1783f31fe4b10f70f27eb490dae433d0845610a862449c37092?d=identicon)[igbas90](/maintainers/igbas90)

---

Tags

apidatayoutubev3

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/igbas90-youtube-data-api/health.svg)

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

###  Alternatives

[pacely/mailchimp-apiv3

Simple API wrapper for Mailchimp API V3

95654.6k2](/packages/pacely-mailchimp-apiv3)[phpfui/constantcontact

Object Oriented Wrapper for Constant Contact API V3 for PHP 8+

2015.7k1](/packages/phpfui-constantcontact)[jeffreyhyer/alpaca-trade-api-php

PHP SDK for the Alpaca trade API

285.0k](/packages/jeffreyhyer-alpaca-trade-api-php)[nextras/youtube-api

Youtube API library for Nette Framework.

1612.8k](/packages/nextras-youtube-api)[sboo/laravel5-mailjet

Mailjet driver for Laravel 5

154.6k](/packages/sboo-laravel5-mailjet)[socialapis/youtubedownloader

A small project for fetching youtube vidoes with their private api.

241.4k](/packages/socialapis-youtubedownloader)

PHPackages © 2026

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