Google Calendar Laravel Api - PullRequest
       31

Google Calendar Laravel Api

0 голосов
/ 02 июня 2018

У меня проблема с подключением календаря к laravel, сообщение о том, что было раньше, является недействительными учетными данными, и я переделываю свои учетные данные моего API в консоли Google, поэтому у меня есть новое, я уже делаю URL-адреса перенаправления aouth и помещаю,Учебник, который я использовал, заключался в том, что https://github.com/webdevmatics/GoogleCalendarApi, все работает нормально, но я нажимаю на секрет повтора и хорошо, что меняю секрет id, я думаю, но я уже все делаю снова, я все еще не работаю, это мой код:

<?php

namespace App\Http\Controllers;

use Carbon\Carbon;
use Google_Client;
use Google_Service_Calendar;
use Google_Service_Calendar_Event;
use Google_Service_Calendar_EventDateTime;
use Illuminate\Http\Request;

use App\Patients;
class CalendarController extends Controller
{
protected $client;

public function __construct()
{
    $client = new Google_Client();
    $client->setAuthConfig('google_calendar.json');
    $client->addScope(Google_Service_Calendar::CALENDAR);

    $guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false)));
    $client->setHttpClient($guzzleClient);
    $this->client = $client;
}

public function view(){
    return view('calendar.index');
}

/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    session_start();
    if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
        $this->client->setAccessToken($_SESSION['access_token']);
        $service = new Google_Service_Calendar($this->client);

        $calendarId = 'primary';

        $results = $service->events->listEvents($calendarId);
        return $results->getItems();

    } else {
        return redirect()->route('oauthCallback');
    }

}

public function oauth()
{
    session_start();

    $rurl = action('CalendarController@oauth');
    $this->client->setRedirectUri($rurl);
    if (!isset($_GET['code'])) {
        $auth_url = $this->client->createAuthUrl();
        $filtered_url = filter_var($auth_url, FILTER_SANITIZE_URL);
        return redirect($filtered_url);
    } else {
        $this->client->authenticate($_GET['code']);
        $_SESSION['access_token'] = $this->client->getAccessToken();
        return redirect()->route('cal.index');
    }
}

Это мой контроллер, google_calendar.json - это файл, который вы загружаете в учетные данные, и ошибка следующая

enter image description here

enter image description here

enter image description here

и мой код для получения событий в jquery следующий

$('#fullCalendar').fullCalendar({
    header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,listYear'
  },

  displayEventTime: false, // don't show the time column in list view

  events: 'gcalendar',

  eventClick: function(event) {
    // opens events in a popup window
    window.open(event.url, 'gcalevent', 'width=700,height=600');
    return false;
  },

  loading: function(bool) {
    $('#loading').toggle(bool);
  }

});

И мои маршруты следующие

Route::resource('gcalendar', 'CalendarController');
Route::get('/calendar', 'CalendarController@view')->name('calendar');
Route::get('/calendar/oauth', 'CalendarController@oauth')->name('oauthCallback');

Извините, если я не очень поясняю, я не очень хорошо понимаю проблему, я уже много чего перепробовал, любая помогает, спасибо

Вы можетепосмотрите демонстрационный проект здесь http://clinic -data.vlmg.mx / tПользователь admin@admin.com и пароль admin, с уважением

...