实施Google Calendar API我收到redirect_uri_mismatch错误

时间:2019-07-08 11:11:56

标签: laravel-5 google-calendar-api

我在ubuntu 18(Digital Ocean)下的域中安装了laravel 5.8应用程序: https://www.votes.nilov-sergey-demo-apps.tk

我尝试在我的应用中实现Google Calendar API,并且可以控制:

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

    }

有路线:

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

使用网址https://www.votes.nilov-sergey-demo-apps.tk/gcalendar运行索引方法时出现重定向错误:

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.

我的应用程序选项为:https://prnt.sc/oc2c3x 使宣誓客户ID我选择“其他” 带有https://www.votes.nilov-sergey-demo-apps.tk的所有选项。

为什么重定向错误以及如何解决?

已修改: 我刚刚注意到 1)我的应用程序主页链接末尾带有“ /”。可能是问题吗?我已修复它,但仍然有问题。 2)在授权域中,当我编辑“ votes.nilov-sergey-demo-apps.tk”时,我看到“ nilov-sergey-demo-apps.tk” 在授权域:https://prnt.sc/ocggqo中输入。可能是问题吗?如何保存为“ votes.nilov-sergey-demo-apps.tk” 正在托管(由https://my.freenom.com制造)我的应用程序(位于Digital ocean下的ubuntu 18上)。

0 个答案:

没有答案