title: Google Calendar Laravel Api
body: <p>I have a problem connecting the calendar with laravel, the message what was before are the invalid credentials and I redo my credentials of my api in google console so I have a new, I already make the aouth redirects urls and put, the tutorial I use was that <a href="https://github.com/webdevmatics/GoogleCalendarApi" rel="nofollow noreferrer">https://github.com/webdevmatics/GoogleCalendarApi</a>, all work fine but I click in redo secret and well that change the id secret I think but I already make all again I still not working this is my code:</p>
  
  <pre><code>&lt;?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-&gt;setAuthConfig('google_calendar.json');
      $client-&gt;addScope(Google_Service_Calendar::CALENDAR);
  
      $guzzleClient = new \GuzzleHttp\Client(array('curl' =&gt; array(CURLOPT_SSL_VERIFYPEER =&gt; false)));
      $client-&gt;setHttpClient($guzzleClient);
      $this-&gt;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']) &amp;&amp; $_SESSION['access_token']) {
          $this-&gt;client-&gt;setAccessToken($_SESSION['access_token']);
          $service = new Google_Service_Calendar($this-&gt;client);
  
          $calendarId = 'primary';
  
          $results = $service-&gt;events-&gt;listEvents($calendarId);
          return $results-&gt;getItems();
  
      } else {
          return redirect()-&gt;route('oauthCallback');
      }
  
  }
  
  public function oauth()
  {
      session_start();
  
      $rurl = action('CalendarController@oauth');
      $this-&gt;client-&gt;setRedirectUri($rurl);
      if (!isset($_GET['code'])) {
          $auth_url = $this-&gt;client-&gt;createAuthUrl();
          $filtered_url = filter_var($auth_url, FILTER_SANITIZE_URL);
          return redirect($filtered_url);
      } else {
          $this-&gt;client-&gt;authenticate($_GET['code']);
          $_SESSION['access_token'] = $this-&gt;client-&gt;getAccessToken();
          return redirect()-&gt;route('cal.index');
      }
  }
  </code></pre>
  
  <p>That is my controller, the google_calendar.json is the file what you download in the credentials, and the error is the next</p>
  
  <p><a href="https://i.stack.imgur.com/UTggl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UTggl.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/gGmXX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gGmXX.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/KtICm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KtICm.png" alt="enter image description here"></a></p>
  
  <p>and my code for get the events in the jquery is the next</p>
  
  <pre><code>$('#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);
    }
  
  });
  </code></pre>
  
  <p>And my routes are the next</p>
  
  <pre><code>Route::resource('gcalendar', 'CalendarController');
  Route::get('/calendar', 'CalendarController@view')-&gt;name('calendar');
  Route::get('/calendar/oauth', 'CalendarController@oauth')-&gt;name('oauthCallback');
  </code></pre>
  
  <p>Sorry if I not very explanatory, I don't understand very well the problem, I already tried many things, any helps thanks</p>
  
  <p>You can view the demo project here <a href="http://clinic-data.vlmg.mx/" rel="nofollow noreferrer">http://clinic-data.vlmg.mx/</a> the user is admin@admin.com and the pass is admin, regards</p>