PHP code example of dynamikaweb / yii2-youtube

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

    

dynamikaweb / yii2-youtube example snippets


'components' => [
    ...
    'youtube' => [
        'class' => \sr1871\youtubeApi\components\YoutubeApi::className(),
        'api_config' => [
            'clientId' => 'your Oauth Client Id, you can get it from google console',
            'clientSecret' => 'your Oauth Client Secret, you can get it from google console',
            'scopes' => ['scopes that you going to use', 'as array'],
        ],
        'channel' = 'youtube channel, which will be consulted'
    ],
    ...
]

public function actionYoutubeValidation() {
    if(Yii::$app->request->get('validate')){
        return $this->redirect(Yii::$app->youtube->validationGet(Yii::$app->urlManager->createAbsoluteUrl('/site/youtube-validation')));
    }

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

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