niisan/laravel-oauth-google-calendar
Composer 安装命令:
composer require niisan/laravel-oauth-google-calendar
包简介
Using Google Calendar Api by using OAuth in Laravel.
README 文档
README
This is a package of a series of processes to create an application linked to Google Calendar using OAuth authentication in Laravel.
Required
Laravel >= 5.8 PHP >= 7.4
Install
Install via composer.
composer require niisan/laravel-oauth-google-calendar
Then, bring the config to your config dir.
php artisan vendor:publish
and choose 'Niisan\Laravel\GoogleCalendar\OauthCalendarServiceProvider'.
You can use this package via DI container.
private OauthCalendarService $oauthCalendarService; public function __construct(OauthCalendarService $oauthCalendarService) { $this->oauthCalendarService = $oauthCalendarService; }
or
$service = app(OauthCalendarService::class);
Config
This package's config file is the google-calendar.php.
<?php return [ 'scopes' => [ 'profile', 'email', 'https://www.googleapis.com/auth/calendar.events', ], 'redirect' => env('GOOGLE_CALENDAR_OAUTH_REDIRECT_URL', 'https://example.com/auth/callback'), 'client_id' => env('GOOGLE_CALENDAR_CLIENT_ID', ''), 'client_secret' => env('GOOGLE_CALENDAR_CLIENT_SECRET', ''), 'events' => [ 'token_refreshed' => '' ], 'holiday_id' => env('GOOGLE_CALENDAR_HOLIDAY_ID', 'japanese__ja@holiday.calendar.google.com'), ];
client_id and client_secret are from Google OAuth user.
holiday_id is your county's calendar id offering holidays.
events.token_refreshed can define a event when token refreshed in this package.
For example,
'events' => [ 'token_refreshed' => TokenRefreshedEvent::class ]
And, Events/TokenRefreshedEvent.php
class TokenRefreshedEvent { use Dispatchable, InteractsWithSockets, SerializesModels; /** * Create a new event instance. * * @return void */ public function __construct($user, array $token) { // }
Usage
This package has following methods.
public function getEventList($user, $config): array; public function createEvent($user, array $data): Google_Service_Calendar_Event; public function deleteEvent($user, $event_id);
These methods take $user as an argument. $user is a object and must huve accessible propeties, access_token, refresh_token, expires.
getEventList()
This method get user's event. $config is a search condition.
$config = [ 'orderBy' => null, 'search' => 'test', 'timeMax' =>'2021-01-01', 'timeMin' => '2020-12-01', 'timeZone' => 'Asia/Tokyo', 'updatedMin' => null 'maxResults' => 150, 'singleEvents' => true ];
All parameters are optional.
createEvent
This method create user's event. $data is a event content.
$data = [ 'summary' => 'abcd', 'description' => 'efgh', 'start' => '2021-02-21 12:00:00', 'end' => '2021-02-21 13:00:00' ];
getFreeBusy
public function getFreeBusy($user, $config): array
This method give you user's busy time. The response type is following:
[
[
'start' => '2021-06-01T02:00:00Z'
'end' => '2021-06-01T04:00:00Z'
],
[
'start' => '2021-06-07T02:00:00Z'
'end' => '2021-06-07T04:00:00Z'
],
]
Note that https://www.googleapis.com/auth/calendar.readonly is the scope that the getFreeBusy method needs to be in.
updateEvent
this method update user's event. $data is same as createEvent's and put null for values that do not need to be updated.
getHolidays
This method offers you your country's holidays.
niisan/laravel-oauth-google-calendar 适用场景与选型建议
niisan/laravel-oauth-google-calendar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30.13k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 niisan/laravel-oauth-google-calendar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 niisan/laravel-oauth-google-calendar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 30.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-18