tilson / laravel-youtube-client
连接YouTube API的简单方法
1.0.0
2023-05-26 23:09 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.5
- illuminate/support: ^10.0
Requires (Dev)
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10.1
This package is auto-updated.
Last update: 2024-09-27 01:56:54 UTC
README
本软件包提供了一种简单直观的方式在YouTube数据API上进行工作。它为YouTube功能提供了流畅的接口。
使用本软件包要实现的目标
- YouTube数据API v3
- 列出我频道的视频
- 列出我的频道播放列表
- 显示频道订阅按钮
安装
composer require tilson/laravel-youtube-client
安装后,在.env文件中定义环境变量API_YOUTUBE_KEY和CHANNEL_ID,它们分别对应API密钥和您的YouTube频道的ID
发布软件包
php artisan vendor:publish --provider="Tilson\YoutubeApi\Providers\YoutubeApiServiceProvider"
在app.php
中注册我们的服务提供者。
// config/app.php 'providers' => ServiceProvider::defaultProviders()->merge([ // ... Tilson\YoutubeApi\Providers\YoutubeApiServiceProvider::class, // ... ])->toArray(),
使用客户端类
use \Tilson\YoutubeApi\Client; $client = app(Client::class); //or Injecting Dependency public function __construct(private Client $client) { // you code }
列出我频道的视频
use \Tilson\YoutubeApi\Client; use \Tilson\YoutubeApi\Enums\OrderBy; $client->lisChannelVideos() ->order(OrderBy::DATE) ->limit(10); ->get();
列出我频道的播放列表
use \Tilson\YoutubeApi\Client; $client->listPlaylists()->limit(10)->get();
显示订阅按钮
<!DOCTYPE html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> @youtubeScriptButton() <--- Add This <title>Laravel</title> </head> <body class="antialiased"> @youtubeButton() <--- Add This (Show the Button) </body> </html>
在youtube_api.php文件中您可以更改按钮的一些设置。
贡献
感谢您考虑为Laravel框架做出贡献!请随时提交您的PR和报告问题。
许可证
本软件包是开源软件,许可协议为MIT。