定制 igbas90/youtube-data-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

igbas90/youtube-data-api

Composer 安装命令:

composer require igbas90/youtube-data-api

包简介

Youtube Data API v3

README 文档

README

Support APIs

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 igbas90/youtube-data-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 33
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-16