igbas90/youtube-data-api
Composer 安装命令:
composer require igbas90/youtube-data-api
包简介
Youtube Data API v3
README 文档
README
Support APIs
- channels.list
- commentsThread.list
- subscriptions.list
- videos.list
- playlistItems.list
- videoCategories.list
Authorization
!!! This library not supported OAuth2, only GOOGLE CONSOLE API KEY
Installation
Run in console below command to download package to your project:
composer require igbas90/youtube-data-api
Usage
Instance
Using a single shell. Services are created when they are accessed
use Igbas90\YoutubeDataApi\YoutubeDataApi; $dataApiClient = new YoutubeDataApi(); $commentsThreadClient = $dataApiClient->commentsThreadList;
Create only service
use Igbas90\YoutubeDataApi\Services\CommentsThreadList; $commentsThreadClient = new CommentsThreadList();
Set params
You can set parameters separately for each service
/** @var $dataApiClient Igbas90\YoutubeDataApi\YoutubeDataApi */ $dataApiClient->commentsThreadList->setApiKey('you google console api key'); $dataApiClient->subscriptionsList->setVideoId('9L9UQANH5oI');
Bulk settings
/** @var $dataApiClient Igbas90\YoutubeDataApi\YoutubeDataApi */ $dataApiClient->commentsThreadList->setParams([ 'apiKey' => "you google console api key", 'params' => [ 'part' => ['part1', 'part2', ...], 'videoId' => 'string or array', ... ] ]);
Parameters such as apiKey, proxy, responseFormatter can be set to services when creating in the shell for this, set these parameters in the shell. After creating the services, you can change these parameters only through the methods of the service itself
use Igbas90\YoutubeDataApi\YoutubeDataApi; $dataApiClient = new YoutubeDataApi([ 'apiKey' => 'your google console api key', 'proxy' => 'http://username:password@ip:port', 'responseFormatter' => new ResponseFormatter() ]);
Usage proxy
To use a proxy server set it to the service
use Igbas90\YoutubeDataApi\YoutubeDataApi; $dataApiClient = new YoutubeDataApi(); //set proxy $dataApiClient->commentsThreadList->setProxy('http://username:password@ip:port'); //reset proxy $dataApiClient->commentsThreadList->resetProxy();
Get result
/** @var $client Igbas90\YoutubeDataApi\Services\CommentsThreadList */ $response = $client->request();
Pagination
For pagination you can manually set pageToken
use Igbas90\YoutubeDataApi\YoutubeDataApi; $client = (new YoutubeDataApi())->commentsThreadList->setParams([...]); $response = $client->setPageToken('pageToken')->request();
The package has built-in support for paging data. An ITERATOR is used for this.
!!!Attention, the client pageToken will be used as the start for the iterator
/** @var $client \Igbas90\YoutubeDataApi\Services\CommentsThreadList*/ $comments = []; foreach($client->getIterator() as $response) { $body = json_decode($response->getBody(), true); $comment = array_merge($comments, $body['items']); }
By default, the iterator works with the original service, which is not very convenient for using multiple iterators. To exclude the influence of the iterator on the service, you can set the iterator to work with the service clone. To do this, call the getIterator() method, with the parameter true.
/** @var $client \Igbas90\YoutubeDataApi\Services\CommentsThreadList*/ $iterator1 = $client->getIterator(true); $iterator2 = $client->setVideoId('videoId')->getIterator(true); $iterator3 = $client->setParams([ 'videoId' => '9L9UQANH5oI', 'apiKey' => 'google console api key' ])->getIterator(true);
Response format
By default, Psr\Http\Message\ResponseInterface is returned If you need to return a different format, then you can specify an object that implements the Igbas90\YoutubeDataApi\Classes\ResponseFormatter interface, which will be used to convert the returned result.
use Igbas90\YoutubeDataApi\Classes\ResponseFormatter; use Psr\Http\Message\ResponseInterface; /* * Create custom response converter */ class BodyJsonDecodeFormatter implements ResponseFormatter { public function format(ResponseInterface $response) { $content = $response->getBody(); return json_decode($content, true); } } /** @var $client Igbas90\YoutubeDataApi\Services\CommentsThreadList */ $client->setResponseFormatter(new BodyJsonDecodeFormatter()); //@var $response array $response = $client->request();
TEST
forward running the tests you need to set the environment variables in define.php, for this just copy define-example.php into define.php
cp define-example.php define.php
replace define.php values with your values.
define("API_KEY", "google console key"); define("PROXY", "http://username:password@ip:port"); define("CHANNEL_ID", "UCf-b4GSsV5HJysCi6A0Bm6g"); define("PLAYLIST_ID", "UU_x5XG1OV2P6uZZ5FSM9Ttw"); define("VIDEO_ID", "oxQ7wfiS4GY");
Documentations
igbas90/youtube-data-api 适用场景与选型建议
igbas90/youtube-data-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「data」 「api」 「youtube」 「v3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 igbas90/youtube-data-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 igbas90/youtube-data-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 igbas90/youtube-data-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
A PSR-7 compatible library for making CRUD API endpoints
♺ Laravel Nova Hashids card. Convert your ids.
统计信息
- 总下载量: 33
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-16