Back

Implement Google Calendar API I got redirect_uri_mismatch er


sergeynilov posted 1 week ago

Hello, I have laravel 5.8 app installed on ubuntu 18( under Digital Ocean ) under domain: https://www.votes.nilov-sergey-demo-apps.tk

I try to implement Google Calendar API in my app and I have control :

app/Http/Controllers/gCalendarController.php

<?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;

class gCalendarController extends Controller
{
    protected $client;

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

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

    /**
     * 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');
        }

    }

with routes :

Route::resource('gcalendar', 'gCalendarController');
Route::get('oauth', ['as' => 'oauthCallback', 'uses' => '[email protected]']);

running index method with url https://www.votes.nilov-sergey-demo-apps.tk/gcalendar I got redirect error :

400. That’s an error.

Error: redirect_uri_mismatch

Request Details
response_type=code
access_type=online
client_id=456883705724-bjk3vme7oo0bf4quno7hkfvaanbc0uej.apps.googleusercontent.com
redirect_uri=https://www.votes.nilov-sergey-demo-apps.tk/oauth
state=
scope=https://www.googleapis.com/auth/calendar
approval_prompt=auto
That’s all we know.

My app options are : https://prnt.sc/oc2c3x All options with https://www.votes.nilov-sergey-demo-apps.tk.

Why redirect error and how to fix it ?

Thanks!

sergeynilov replied 1 week ago

I have just payed attention that

  1. my application home Link had “/” at end. Could it be the issue? I fixed it but still having problems.

  2. When in Authorized Domains I edit “votes.nilov-sergey-demo-apps.tk” I see that “nilov-sergey-demo-apps.tk” is entered in Authorized Domains : https://prnt.sc/ocggqo. Can it be the issue? How can it be salved, as "votes.nilov-sergey-demo-apps.tk" is hosting (made in https://my.freenom.com) of my app (located on ubuntu 18 under Digital ocean ).


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us