PHP code example of menincode / yii2-youtube-api

1. Go to this page and download the library: Download menincode/yii2-youtube-api 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/ */

    

menincode / yii2-youtube-api example snippets


'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}'],
    ],
    ...
]

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');
    }
}

'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
],

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