sdsmith1981/youtube
最新稳定版本:v1.0.3
Composer 安装命令:
composer require sdsmith1981/youtube
包简介
Laravel PHP Facade/Wrapper for the Youtube Data API v3
README 文档
README
Laravel PHP Facade/Wrapper for the Youtube Data API v3 ( Non-OAuth )
You need to create an application and create your access token in the developer console.
Installation
Run in console below command to download package to your project:
composer require sdsmith1981/youtube --prefer-dist dev-master
Configuration
For Laravel 5
In /config/app.php add YoutubeServiceProvider:
SdSmith1981\Youtube\YoutubeServiceProvider::class,
Do not forget to add also Youtube facade there:
'Youtube' => SdSmith1981\Youtube\Facades\Youtube::class,
Publish config settings:
php artisan vendor:publish
Set your Youtube API key in the file:
/config/youtube.php
Usage
// use SdSmith1981\Youtube\Facades\Youtube; // Return an STD PHP object $video = Youtube::getVideoInfo('rie-hPVJ7Sw'); // Get multiple videos info from an array $videoList = Youtube::getVideoInfo(['rie-hPVJ7Sw','iKHTawgyKWQ']); // Get multiple videos related to a video $relatedVideos = Youtube::getRelatedVideos('iKHTawgyKWQ'); // Get popular videos in a country, return an array of PHP objects $videoList = Youtube::getPopularVideos('us'); // Search playlists, channels and videos. return an array of PHP objects $results = Youtube::search('Android'); // Only search videos, return an array of PHP objects $videoList = Youtube::searchVideos('Android'); // Search only videos in a given channel, return an array of PHP objects $videoList = Youtube::searchChannelVideos('keyword', 'UCk1SpWNzOs4MYmr0uICEntg', 40); // List videos in a given channel, return an array of PHP objects $videoList = Youtube::listChannelVideos('UCk1SpWNzOs4MYmr0uICEntg', 40); $results = Youtube::searchAdvanced(array( /* params */ )); // Get channel data by channel name, return an STD PHP object $channel = Youtube::getChannelByName('xdadevelopers'); // Get channel data by channel ID, return an STD PHP object $channel = Youtube::getChannelById('UCk1SpWNzOs4MYmr0uICEntg'); // Get playlist by ID, return an STD PHP object $playlist = Youtube::getPlaylistById('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs'); // Get playlist by channel ID, return an array of PHP objects $playlists = Youtube::getPlaylistsByChannelId('UCk1SpWNzOs4MYmr0uICEntg'); // Get items in a playlist by playlist ID, return an array of PHP objects $playlistItems = Youtube::getPlaylistItemsByPlaylistId('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs'); // Get channel activities by channel ID, return an array of PHP objects $activities = Youtube::getActivitiesByChannelId('UCk1SpWNzOs4MYmr0uICEntg'); // Retrieve video ID from original YouTube URL $videoId = Youtube::parseVidFromURL('https://www.youtube.com/watch?v=moSFlvxnbgk'); // result: moSFlvxnbgk
Basic Search Pagination
// Set default parameters $params = array( 'q' => 'Android', 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => 50 ); // Make intial call. with second argument to reveal page info such as page tokens $search = Youtube::searchAdvanced($params, true); // Check if we have a pageToken if (isset($search['info']['nextPageToken'])) { $params['pageToken'] = $search['info']['nextPageToken']; } // Make another call and repeat $search = Youtube::searchAdvanced($params, true); // Add results key with info parameter set print_r($search['results']); /* Alternative approach with new built-in paginateResults function */ // Same params as before $params = array( 'q' => 'Android', 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => 50 ); // An array to store page tokens so we can go back and forth $pageTokens = array(); // Make inital search $search = Youtube::paginateResults($params, null); // Store token $pageTokens[] = $search['info']['nextPageToken']; // Go to next page in result $search = Youtube::paginateResults($params, $pageTokens[0]); // Store token $pageTokens[] = $search['info']['nextPageToken']; // Go to next page in result $search = Youtube::paginateResults($params, $pageTokens[1]); // Store token $pageTokens[] = $search['info']['nextPageToken']; // Go back a page $search = Youtube::paginateResults($params, $pageTokens[0]); // Add results key with info parameter set print_r($search['results']);
The pagination above is quite basic. Depending on what you are trying to achieve you may want to create a recursive function that traverses the results.
Run Unit Test
If you have PHPUnit installed in your environment, run:
$ phpunit
If you don't have PHPUnit installed, you can run the following:
$ composer update $ ./vendor/bin/phpunit
Format of returned data
The returned JSON is decoded as PHP objects (not Array). Please read the "Reference" section of the Official API doc.
Youtube Data API v3
Credits
Built on code from Madcoda's php-youtube-api and Alaouy's (https://github.com/alaouy/Youtube)
sdsmith1981/youtube 适用场景与选型建议
sdsmith1981/youtube 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 118.99k 次下载、GitHub Stars 达 1, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「youtube」 「video」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sdsmith1981/youtube 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sdsmith1981/youtube 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sdsmith1981/youtube 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
The yii2-videojs-widget is a Yii 2 wrapper for the [video.js](http://www.videojs.com/). A JavaScript and CSS library that makes it easier to work with and build on HTML5 video. This is also known as an HTML5 Video Player.
A PSR-7 compatible library for making CRUD API endpoints
♺ Laravel Nova Hashids card. Convert your ids.
Display a video using native HTML5 video
Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers
统计信息
- 总下载量: 118.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知