arm092/youtuber-for-laravel
Composer 安装命令:
composer require arm092/youtuber-for-laravel
包简介
The package will help you to upload videos to youtube with privacy parameter and making youtube api much easier
README 文档
README
laravel youtube uploader is a php package written by Arman Khachatryan with laravel to handle many youtube sdk functionality by making it's api more easy.
Features
- Uploading videos to user channel
- Creating playlists
- Insert video to existing playlist
- Set thumbnail to existing video or at uploading video
- Deleting video
Installation Guide
At laravel project install package using composer
composer require arm092/youtuber-for-laravel
The package is compatible with Laravel 6.x so you don't need to set providers or aliases for the package, we're using laravel auto discovery
Get Your Credentials From Google
- Go to Google Developers Console Press Credentials from the sidebar then create project from OAuth consent screen then Click Credentials => Create credentials => OAuth client id, choose it web application and set you Authorized redirect URIs, also you can edit or add new urls later
- You will get Client Id and Client Secret
- Go to your .env file and paste your credentials to be like this
GOOGLE_CLIENT_ID=YOUR_CLIENT_ID
GOOGLE_CLIENT_SECRET=YOUR_SECRET
You are now ready to use the package
There is two steps to do any thing for the package, get authenticated url and do the youtube api action
To get the auth url, just go to routes/web.php and do this route or the path you want to use
Route::get('youtube/auth', 'YoutubeUploaderController@auth');
At the controller, you will get the url and you can show it in view file or redirect user to it directly
use Youtube;
public function auth() {
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback'; // Upload video path
return redirect(Youtube::setRedirectUrl($redirect_url)->AuthUrl());
}
This code will authenticate user then redirect user to another url to do your logic on it, and to do any logic code, you need to add route url to routes/web.php
Route::get('youtube/callback', 'YoutubeUploaderController@callback');
Don't forget to save full path of callback url at google console developer at credential for project
The we will now show our logic of the package
Upload video
public function callback(Request $request) {
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback';
$video = public_path('VIDEO_FILE');
$image = public_path('IMAGE_FILE');
$youtube = Youtube::setRedirectUrl($redirect_url)->upload($video,
[
'title' => 'TITLE',
'description' => 'DESCRIPTION',
'tags' => ['tag 1', 'tag 2'],
'category_id' => '22',
'privacy' => 'public' // or 'private' and 'unlisted'
]
);
// Get uploaded video id
$video_id = $youtube->uploadedVideoId();
}
Set thumbnail to existing video
Remember that you need to set auth url at routes for each callback url
public function another_callback(Request $request) {
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
$video_id = 'VIDEO_ID';
$image = public_path('THUMBNAIL_PATH');
$youtube = Youtube::setRedirectUrl($redirect_url)->updateThumbnail($video_id, $image);
}
Set thumbnail at uploading
Remember that you need to set auth url at routes for each callback url
public function another_callback(Request $request) {
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
$video = public_path('VIDEO_PATH');
$image = public_path('THUMBNAIL_PATH');
$youtube = Youtube::setRedirectUrl($redirect_url)->upload($video,
[
'title' => 'TITLE',
'description' => 'Description1',
'tags' => ['tag 1', 'tag2'],
'category_id' => '22',
'privacy' => 'public' // or 'private' and 'unlisted'
]
)->withThumbnail($image);
$video_id = $youtube->uploadedVideoId();
}
Set tags for existing video
Remember that you need to set auth url at routes for each callback url
public function another_callback(Request $request) {
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
$video_id = 'YOUR_VIDEO_ID';
$youtube = Youtube::setRedirectUrl($redirect_url)->updateTags($video_id, ['tag 1', 'tag2', 'Tag3', 'Tag 4']);
}
Create Playlist
Remember that you need to set auth url at routes for each callback url
public function another_callback(Request $request) {
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
$youtube = Youtube::setRedirectUrl($redirect_url)
->createPlaylist('TITLE', 'DESCRIPTION');
// Get playlist id
$playlist_id = $youtube->createdPlaylistId();
}
Insert Video to playlist
Remember that you need to set auth url at routes for each callback url
public function another_callback(Request $request) {
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
$youtube = Youtube::setRedirectUrl($redirect_url)
->VideoToPlaylist('VIDEO_ID', 'PLAYLIST_ID');
}
Delete video by the given id
Remember that you need to set auth url at routes for each callback url
public function another_callback(Request $request) {
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
$video_id = 'VIDEO_ID';
$youtube = Youtube::setRedirectUrl($redirect_url)->deleteVideo($video_id);
}
arm092/youtuber-for-laravel 适用场景与选型建议
arm092/youtuber-for-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 8, 最近一次更新时间为 2023 年 04 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 arm092/youtuber-for-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arm092/youtuber-for-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-01