在Codeigniter 3中使用Google日历

时间:2019-06-20 06:05:08

标签: php api codeigniter google-calendar-api

我正在关注此链接https://github.com/omerkamcili/ci_google_calendar_api 用于在Codeigniter中集成Google日历。我有 得到了所有凭证。但是当我运行这个应用程序 每次都会让我回到http://hostname/auth/login 它登录到应用程序。当我调试它时,不会生成令牌。

  

型号:Googlecalendar.php

public class App {
    public static void main( String[] args ) {
        HangMen hangMen = new HangMen() ;  // Invokes your constructor implicitly. At runtime, the class `HangMen` (note the uppercase `H`) is used to create a new instance (new object). A reference to the object is assigned to the variable named `hangMen` (note the lowercase `h`).
        hangMen.report() ;                 // Invokes the `report` method for this instance (this object). 
    }
}
  

型号:Auth.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Googlecalendar extends CI_Model
{

    public function __construct()
    {

        parent::__construct();
        $this->load->library('session');
        $this->load->library('googleplus');
        $this->calendar = new Google_Service_Calendar($this->googleplus->client());



    }


    public function isLogin()
    {


        $token = $this->session
            ->userdata('google_calendar_access_token');

        if ($token) {

            $this->googleplus
                ->client
                ->setAccessToken($token);

        }

        if ($this->googleplus->isAccessTokenExpired()) {

            return false;

        }

        return $token;

    }


    public function loginUrl()
    {

        return $this->googleplus
            ->loginUrl();

    }


    public function login($code)
    {

        $login = $this->googleplus
            ->client
            ->authenticate($code);

        if ($login) {

            $token = $this->googleplus
                ->client
                ->getAccessToken();

            $this->session
                ->set_userdata('google_calendar_access_token', $token);

            return true;

        }

    }


    public function getUserInfo()
    {

        return $this->googleplus->getUser();

    }


    public function getEvents($calendarId = 'primary', $timeMin = false, $timeMax = false, $maxResults = 10)
    {


        if ( ! $timeMin) {

            $timeMin = date("c", strtotime(date('Y-m-d ').' 00:00:00'));

        } else {

            $timeMin = date("c", strtotime($timeMin));

        }


        if ( ! $timeMax) {

            $timeMax = date("c", strtotime(date('Y-m-d ').' 23:59:59'));

        } else {

            $timeMax = date("c", strtotime($timeMax));

        }


        $optParams = array(
            'maxResults'   => $maxResults,
            'orderBy'      => 'startTime',
            'singleEvents' => true,
            'timeMin'      => $timeMin,
            'timeMax'      => $timeMax,
            'timeZone'     => 'Europe/Istanbul',

        );

        $results = $this->googlecalendar->calendar->events->listEvents($calendarId, $optParams);


        $data = array();

        foreach ($results->getItems() as $item) {

            $start = date('d-m-Y H:i', strtotime($item->getStart()->dateTime));

            array_push(

                $data,
                array(

                    'id'          => $item->getId(),
                    'summary'     => $item->getSummary(),
                    'description' => $item->getDescription(),
                    'creator'     => $item->getCreator(),
                    'start'       => $item->getStart()->dateTime,
                    'end'         => $item->getEnd()->dateTime,


                )

            );

        }

        return $data;

    }


    public function addEvent($calendarId = 'primary', $data)
    {


        //date format is => 2016-06-18T17:00:00+03:00

        $event = new Google_Service_Calendar_Event(
            array(
                'summary'     => $data['summary'],
                'description' => $data['description'],
                'start'       => array(
                    'dateTime' => $data['start'],
                    'timeZone' => 'Europe/Istanbul',
                ),
                'end'         => array(
                    'dateTime' => $data['start'],
                    'timeZone' => 'Europe/Istanbul',
                ),
                'attendees'   => array(
                    array('email' => 'omerkamcili@gmail.com'),
                ),
            )
        );


        return $this->calendar->events->insert($calendarId, $event);


    }


}

1 个答案:

答案 0 :(得分:0)

如果您在解析特定名称时遇到问题,并且想验证问题是否出在Google Public DNS上,请首先尝试在https://dns.google.com上解决该域。如果结果不能查明问题,则可以运行以下诊断过程。检查此documentation以获得更多详细信息。