fungio/google-calendar-bundle

为您的 Symfony 3 项目提供 Google 日历集成。

dev-master / 4.3.x-dev 2020-06-11 14:13 UTC

This package is auto-updated.

Last update: 2024-09-11 22:53:30 UTC


README

此包使用 Google API 列出、创建或更新 Google 日历中的事件。

请随意贡献、分支、发送合并请求和创建工单。

要求

创建 API 账户

前往开发者控制台: https://console.developers.google.com

创建 OAuth ID。不要忘记重定向 URI。

点击“下载 JSON”以获取 client_secret.json

安装

步骤 1:安装 GoogleCalendarBundle

运行

composer require fungio/google-calendar-bundle:dev-master

步骤 2:启用包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Fungio\GoogleCalendarBundle\FungioGoogleCalendarBundle()
    ];
}

步骤 3:配置

将您的 client_secret.json 文件复制到例如 app/Resources/GoogleCalendarBundle/client_secret.json

# app/config/parameters.yml

fungio_google_calendar:
    google_calendar:
        application_name: "Google Calendar"
        credentials_path: "%kernel.root_dir%/.credentials/calendar.json"
        client_secret_path: "%kernel.root_dir%/Resources/GoogleCalendarBundle/client_secret.json"

示例

<?php
// in a controller
$request = $this->get('request_stack')->getMasterRequest();

$googleCalendar = $this->get('fungio.google_calendar');
$googleCalendar->setRedirectUri($redirectUri);

if ($request->query->has('code') && $request->get('code')) {
    $client = $googleCalendar->getClient($request->get('code'));
} else {
    $client = $googleCalendar->getClient();
}

if (is_string($client)) {
    return new RedirectResponse($client);
}

$events = $googleCalendar->getEventsForDate('primary', new \DateTime('now');