marcusyan/youtube-laravel-api
Composer 安装命令:
composer require marcusyan/youtube-laravel-api
包简介
It is a wrapper over Youtube Api v3 which simplifies functionalities the laravel way.
关键字:
README 文档
README
PHP (Laravel) Package for Google / YouTube API V3 with Google Auth
Features
Installation
composer require alchemyguy/youtube-laravel-api
Add Service provider to config/app.php provider's array:
alchemyguy\YoutubeLaravelApi\YoutubeLaravelApiServiceProvider::class
Execute the following command to get the configurations:
php artisan vendor:publish --tag='youtube-config'
Steps to create your google oauth credentials:
- Goto
https://console.developers.google.com - Login with your credentials & then create a new project.
- Enable the following features while creating key
- Youtube Data API
- Youtube Analytics API
- Youtube Reporting API
- Then create
API keyfrom credentials tab. - Then in OAuth Consent Screen enter the
product name(your site name). - create credentials > select OAuth Client ID. (here you will get client_id and client_secret)
- Then in the Authorized Javascript Origins section add
you site url. - In the Authorized Redirect URLs section add
add a url which you want the auth code to return(login callback) - You will get values (to be exact - client_id, client_secret & api_key)
- Then add these values - client_id, client_secret, api_key and redirect_url in the env file and you can start using the package now.
Usage :
Google Auth
- Add Code to call the api class
<?php namespace Your\App\NameSpace; use alchemyguy\YoutubeLaravelApi\AuthenticateService;
- Generating an Auth-Url
$authObject = new AuthenticateService; # Replace the identifier with a unqiue identifier for account or channel $authUrl = $authObject->getLoginUrl('email','identifier');
- Fetching the Auth Code and Identifier Now once the user authorizes by visiting the url, the authcode will be redirected to the redirect_url specified in .env with params as code( this will be auth code) and state (this will be identifier we added during making the loginUrl)
$code = Input::get('code'); $identifier = Input::get('state');
- Auth-Token and Details For Channel
$authObject = new AuthenticateService; $authResponse = $authObject->authChannelWithCode($code);
- This will return an array:
$authResponse['token'] (Channel Token)
$authResponse['channel_details']
$authResponse['live_streaming_status'] (enabled or disabled)
Full Live Streaming API
- Add Code to call the api class
<?php namespace Your\App\NameSpace; use alchemyguy\YoutubeLaravelApi\LiveStreamService;
- Creating a Youtube Event
# data format creating live event $data = array( "title" => "", "description" => "", "thumbnail_path" => "", // Optional "event_start_date_time" => "", "event_end_date_time" => "", // Optional "time_zone" => "", 'privacy_status' => "", // default: "public" OR "private" "language_name" => "", // default: "English" "tag_array" => "" // Optional and should not be more than 500 characters ); $ytEventObj = new LiveStreamService(); /** * The broadcast function returns array of details from YouTube. * Store this information & will be required to supply to youtube * for live streaming using encoder of your choice. */ $response = $ytEventObj->broadcast($authToken, $data); if ( !empty($response) ) { $youtubeEventId = $response['broadcast_response']['id']; $serverUrl = $response['stream_response']['cdn']->ingestionInfo->ingestionAddress; $serverKey = $response['stream_response']['cdn']->ingestionInfo->streamName; }
- Updating a Youtube Event
$ytEventObj = new LiveStreamService(); /** * The updateBroadcast response give details of the youtube_event_id,server_url and server_key. * The server_url & server_key gets updated in the process. (save the updated server_key and server_url). */ $response = $ytEventObj->updateBroadcast($authToken, $data, $youtubeEventId); // $youtubeEventId = $response['broadcast_response']['id']; // $serverUrl = $response['stream_response']['cdn']->ingestionInfo->ingestionAddress; // $serverKey = $response['stream_response']['cdn']->ingestionInfo->streamName
- Deleting a Youtube Event
$ytEventObj = new LiveStreamService(); # Deleting the event requires authentication token for the channel in which the event is created and the youtube_event_id $ytEventObj->deleteEvent($authToken, $youtubeEventId);
- Starting a Youtube Event Stream:
$ytEventObj = new LiveStreamService(); /** * $broadcastStatus - ["testing", "live"] * Starting the event takes place in 3 steps * 1. Start sending the stream to the server_url via server_key recieved as a response in creating the event via the encoder of your choice. * 2. Once stream sending has started, stream test should be done by passing $broadcastStatus="testing" & it will return response for stream status. * 3. If transitioEvent() returns successfull for testing broadcast status, then start live streaming your video by passing $broadcastStatus="live" * & in response it will return us the stream status. */ $streamStatus = $ytEventObj->transitionEvent($authToken, $youtubeEventId, $broadcastStatus);
- Stopping a Youtube Event Stream
$ytEventObj = new LiveStreamService(); /** * $broadcastStatus - ["complete"] * Once live streaming gets started succesfully. We can stop the streaming the video by passing broadcastStatus="complete" and in response it will give us the stream status. */ $ytEventObj->transitionEvent($authToken, $youtubeEventId, $broadcastStatus); // $broadcastStatus = ["complete"]
Full Youtube Channel API
- Add Code to call the api class
<?php namespace Your\App\NameSpace; use alchemyguy\YoutubeLaravelApi\ChannelService;
- Channel details By Channel Id
If you want channel details for multiple channels add channel id saperated by commas(,) in param
NOTE: This doesn't require authorization token
/** * [channelsListById -gets the channnel details and ] * $part 'id,snippet,contentDetails,status, statistics, contentOwnerDetails, brandingSettings' * $params [array channels id(comma separated ids ) or you can get ('forUsername' => 'GoogleDevelopers')] */ $part = 'id,snippet'; $params = array('id'=> 'channel_1_id,channel_2_id'); $channelServiceObject = new ChannelService; $channelDetails = $channelServiceObject->channelsListById($part, $params);
- Channel Detail by Token Channel Details of the users channel which has authorized token
$channelServiceObject = new ChannelService; $channelDetails = $channelServiceObject->getChannelDetails($authToken);
- Channel Subscription List List of subscriptions of the channel
/* * $params array('channel_id'=>'', * 'max_results'= 10) */ $channelServiceObject = new ChannelService; $channelDetails = $channelServiceObject->subscriptionByChannelId($params);
- Add Subscriptions For Authorized Channel
/* * properties array('snippet.resourceId.kind' => 'youtube#channel','snippet.resourceId.channelId' => 'UCqIOaYtQak4-FD2-yI7hFkw') */ $channelServiceObject = new ChannelService; $response = $channelServiceObject->addSubscriptions($properties, $token, $part='snippet', $params=[]);
-Remove Subscriptions For Authorized Channel To remove subscription we need subscription id which can be found from subscription list.
$response = $channelServiceObject->removeSubscription( $token, $subscriptionId);
- Update Channel Branding Settings Updates the channel details and preferences.
/* * $properties array('id' => '', * 'brandingSettings.channel.description' => '', * 'brandingSettings.channel.keywords' => '', * 'brandingSettings.channel.defaultLanguage' => '', * 'brandingSettings.channel.defaultTab' => '', * 'brandingSettings.channel.moderateComments' => '', * 'brandingSettings.channel.showRelatedChannels' => '', * 'brandingSettings.channel.showBrowseView' => '', * 'brandingSettings.channel.featuredChannelsTitle' => '', * 'brandingSettings.channel.featuredChannelsUrls[]' => '', * 'brandingSettings.channel.unsubscribedTrailer' => '') */ $channelServiceObject = new ChannelService; $response = $channelServiceObject->updateChannelBrandingSettings($googleToken, $properties);
Full Youtube Video API
- Add Code to call the api class
<?php namespace Your\App\NameSpace; use alchemyguy\YoutubeLaravelApi\VideoService;
- List Video By Id
$part ='snippet,contentDetails,id,statistics'; $params =array('id'=>'xyzgh'); $videoServiceObject = new VideoService; $response = $videoServiceObject->videosListById($part, $params);
- Upload Video To Your Channel
/* * $videoPath path to the video * $data array('title'=>"", * 'description'=>"", * 'tags'=>"", * 'category_id'=>"", * 'video_status'=>"") */ $videoServiceObject = new VideoService; $response = $videoServiceObject->uploadVideo($googleToken, $videoPath, $data);
- Delete Video To Your Channel
$videoServiceObject = new VideoService; $response = $videoServiceObject->deleteVideo($googleToken, $videoId);
- Rate Video Adding a like, dislike or removing the response from video
# rating 'like' or 'dislike' or 'none' $videoServiceObject = new VideoService; $response = $videoServiceObject->videosRate($googleToken, $videoId, $rating);
marcusyan/youtube-laravel-api 适用场景与选型建议
marcusyan/youtube-laravel-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.11k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「oauth」 「laravel」 「google api」 「AlchemyGuy」 「YoutubeLaravelApi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marcusyan/youtube-laravel-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marcusyan/youtube-laravel-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marcusyan/youtube-laravel-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WeChat OAuth SDK
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Alfabank REST API integration
OAuth 2.0 资源服务器扩展插件
统计信息
- 总下载量: 1.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-08