PHPackages                             menincode/yii2-youtube-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. menincode/yii2-youtube-api

ActiveYii2-extension[API Development](/categories/api)

menincode/yii2-youtube-api
==========================

Component for use youtube api with Oauth in yii2

1.0.2(4y ago)05GPL-3.0+PHP &gt;=7.0

Since Aug 31Compare

[ Source](https://github.com/menincode/yii2-youtube-api)[ Packagist](https://packagist.org/packages/menincode/yii2-youtube-api)[ RSS](/packages/menincode-yii2-youtube-api/feed)WikiDiscussions Synced today

READMEChangelogDependencies (2)Versions (4)Used By (0)

Youtube Api for yii2
====================

[](#youtube-api-for-yii2)

Youtube api is a yii2 extension to use youtube api as a yii2 component.

this extension access youtube api via oauth, saving the access token and refresh it when expire, so you have to give credentials just once

This extension also contains methods for partners, so you don't have to put your onBehalfContentOwner every single call, and control the youtube partner calls per minute to avoid overflow of limit call per minute

With this extension you can

- upload and update a videos
- upload a thumbnail for a video
- list of videos
- create and update playlists
- get ,add and remove elements for a playlist
- searches
- Put the player

Also can do partener actions like

- get channels
- monetize/unmonetize videos

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

[](#installation)

The preferred way to install this extension is through composer.

`$ composer require sr1871/yii2-youtube-api`

Usage
-----

[](#usage)

Add it to your components

### add to your components

[](#add-to-your-components)

```
'components' => [
    ...
    'youtube' => [
        'class' => \sr1871\youtubeApi\components\YoutubeApi::className(),
        'clientId' => '{your Oauth Client Id, you can get it from google console}',
        'clientSecret' => '{your Oauth Client Secret, you can get it from google console}',
        'setAccessTokenFunction' => function($client){ file_put_contents('pathFile.txt'json_encode($client->getAccessToken());}, //anonymous function where save the accesToken
        'getAccessTokenFunction' => function(){ return file_get_contents('pathFile.txt');}, // an anonymous function where get the accessToken
        'scopes' => ['{scopes that you going to use}', '{as array}'],
    ],
    ...
]

```

`setAccessTokenFunction` and `getAccessTokenFunction` are so important, in one you gonna save your accessToken and another let the component take it.

In the example above, the access token was save it in txt, and in te function to take it return the content of that file.

It's important that you `setAccessTokenFunction` has one parameter (`$client` for example) and always save only `json_encode($client->getAccessToken)`.

### generate your access token

[](#generate-your-access-token)

An advantage of this component is that you only have to generate your access token once.

Create an action in any controller

```
public function actionValidation() {
    if(Yii::$app->request->get('code')){
        Yii::$app->youtube->validationPost(Yii::$app->urlManager->createAbsoluteUrl('/site/validation'));
    } else {
        Yii::$app->session->setFlash('success', 'The access token was generated');
        return $this->redirect('index');
    }
}

```

You can call your action as you want, when has a GET parameter called 'code', you must call `Yii::$app->youtube->validationPost('{url_to_this_action}')` , this method create and save the access token and redirect to the url passed as parameter.

To get this action you must do it through `Yii::$app->youtube->validationGet(Yii::$app->urlManager->createAbsoluteUrl({url_to_action}))`, you can use it for example in a `` tag

for example

`echo Html::a('Validar', Yii::$app->youtube->validationGet(Yii::$app->urlManager->createAbsoluteUrl('/site/validation')) )`

The access token'll be saved and you can use the component

### Example

[](#example)

`Yii::$app->youtube->setParts(['snippet', 'recordingDetails', 'id'])->listVideos(['id' => 'someId'])`

You can pass in `setParts()`, the parts that you want, if you don't want the default parts. For more information of every method and how do it, read the PhpDOC of component's methods

### Partner

[](#partner)

if you want to use the extension as a partner you must indicate your `onBehalfContentOwner` in your config

```
'youtube' => [
    'class' => \sr1871\youtubeApi\components\YoutubeApi::className(),
    'clientId' => '{your Oauth Client Id, you can get it from google console}',
    'clientSecret' => '{your Oauth Client Secret, you can get it from google console}',
    'setAccessTokenFunction' => function($client){ file_put_contents('pathFile.txt'json_encode($client->getAccessToken());}, //anonymous function where save the accesToken
    'getAccessTokenFunction' => function(){ return file_get_contents('pathFile.txt');}, // an anonymous function where get the accessToken
    'scopes' => ['{scopes that you going to use}', '{as array}'],
    'onBehalfContentOwner' => {your_content_owner},
    'youtubePartnerCallsPerSecond' => 2 //you can indicate how many calls per second can you do, default is 2
],

```

If you don't know your `onBehalfContentOwner` you can get it with `getOnBehalfOfContentOwner()` method

### Player

[](#player)

This extension include a player in widget format

```
\sr1871\youtubeApi\widgets\YoutubeIFrame::widget([
    'id' => 'SomeIdForDivAndJSObject'
    'iFrameOptions' => [
        'videoId' => 'someId'
        ...
    ],
    'iFrameEvents' => [
        'onReady' => 'function(event) {
            console.log('ready')
        }'
    ],
    'options' => [] //html div options
])

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~561 days

Total

3

Last Release

1741d ago

### Community

Maintainers

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

---

Top Contributors

[![ericng-arch](https://avatars.githubusercontent.com/u/229669545?v=4)](https://github.com/ericng-arch "ericng-arch (2 commits)")[![sr1871](https://avatars.githubusercontent.com/u/24658476?v=4)](https://github.com/sr1871 "sr1871 (1 commits)")

---

Tags

apivideoyoutubeyii2extension

### Embed Badge

![Health badge](/badges/menincode-yii2-youtube-api/health.svg)

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

###  Alternatives

[mikemadisonweb/yii2-elasticsearch

Yii2 extension for integration with Elasticsearch version 5.0 and above.

164.1k](/packages/mikemadisonweb-yii2-elasticsearch)[apexwire/yii2-restclient

Tools to use API as ActiveRecord for Yii2

143.5k](/packages/apexwire-yii2-restclient)

PHPackages © 2026

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