billyriantono/youtube
Composer 安装命令:
composer require billyriantono/youtube
包简介
YouTube API Wrapper with Laravel 5.
README 文档
README
Based on Dawson/Youtube
If you've ever needed to upload videos to a single YouTube channel or you need request data from your Laravel 5 application, then hopefully this is the package for you.
Installation
Add the following to your composer.json.
"billyriantono/youtube": "dev-master"
After you've added the above, run composer update to pull it in. Once your update has finished, we'll need to add the service provider to your config/app.php
'providers' => [ 'billyriantono\Youtube\YoutubeServiceProvider', ],
Then add the alias...
'aliases' => [ 'Youtube' => 'billyriantono\Youtube\YoutubeFacade', ],
Configuration
Run php artisan vendor:publish to publish the migrations and config. Then migrate the database with, php artisan migrate.
This will create our youtube_access_tokens and channels table which will of course, hold our access tokens once we've authenticated with Google.
Next it's time to configure our settings in config/youtube.php makes use of environment variables to ensure no secret crentials make way into version control. So add the following variables to your .env file.
GOOGLE_CLIENT_ID=YOUR_CLIENT_ID
GOOGLE_CLIENT_SECRET=YOUR_SECRET
YOUTUBE_APPLICATION_NAME="Your Application Name"
YOUTUBE_REDIRECT_URI="Your Callback Uri" for example : youtube-callback
YOUTUBE_AUTHENTICATION_URI="Your Authentication Uri"
YOUTUBE_AFTER_REDIRECT_URI="Your Custom Controller after getting access token"
GOOGLE_APPROVAL_PROMPT="auto|force"
You can find these values on Google's developer console for your application.
Now set up your applications callback, you can find this on your config/youtube.php. By default it's set to http://yourapp.co.uk/youtube-callback
'redirect_uri' => 'youtube-callback'
If you're unsure of how to use enviroment variables, Jeffrey Way helps clear the fog over at Laracasts with his Environments and Configuration lesson with Laravel 5.
Authentication
Now our application is configured, we'll go through the inital authentication with Google. By default, the authorization route is /youtube-auth but you can change this in config/youtube.php should you wish to.
Proceed with hitting the auth route in your application of which you will be sent to Google to authorize your YouTube account/channel. Once authorized, you will be redirected back to your application assuming you correctly configured your callback.
Upload a Video
Once you have complete the above, your Laravel application will now be authorized to make requests to YouTube. Specifically in this case, uploading a video by passing the full path to the file you wish to upload..
To upload a video, do the following:
$id = Youtube::upload($pathToMovieFile); return $id;
The above will return the ID of the uploaded video to YouTube.
You also have the option to pass a second parameter as an array with the following available keys.
- title
string - description
string - category_id
integer - tags
array
$params = [ 'title' => 'Laravel Screencast', 'description' => 'My First Laravel Tutorial!', 'category_id' => 10, 'tags' => [ 'laravel', 'eloquent', 'awesome' // Of course! ] ]; $id = Youtube::upload($pathToMovieFile, $params); return $id;
It's that simple!
Deleting a Video
If you would like to delete a video, which of course is uploaded to your authorized channel, you will also have the ability to delete it:
Youtube::delete($id);
When deleting a video, it will check if exists before attempting to delete.
Questions
Should you have any questions, please feel free to submit an issue.
billyriantono/youtube 适用场景与选型建议
billyriantono/youtube 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 billyriantono/youtube 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 billyriantono/youtube 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-21