dynamikaweb / yii2-youtube
environment for use with youtube, has validators, helpers, apis, widgets...
Installs: 730
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Type:yii2-extension
Requires
- sr1871/yii2-youtube-api: dev-master
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-10-25 02:14:56 UTC
README
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require dynamikaweb/yii2-youtube "*"
or add
"dynamikaweb/yii2-youtube": "*"
to the require
section of your composer.json
file.
Usage
Add it to your components
add to your components
'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' ], ... ]
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 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'); } }
To validate access to the action by passing the validate
parameter come true.
This will access google to do the validation and it will return to the same action by passing the parameter code
with the Access Token
.
Example:
https://yoursite.com.br/site/youtube-validation?validate=1
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