我进入浏览器无法使用谷歌日历 api 接收访问令牌

问题描述

我正在尝试开始使用 google api(日历),但我无法完成。我的目的是以编程方式添加事件。我在授权应用程序后收到消息“错误:无法接收访问令牌”。我配置了项目,访问令牌,允许写日历..这是我的php代码

<?php
session_start();

require_once('google-calendar-api.php');
require_once('settings.php');

// Google passes a parameter 'code' in the Redirect Url
if(isset($_GET['code'])) {
    try {
        $capi = new GoogleCalendarApi();
        
        // Get the access token 
        $data = $capi->GetAccessToken(CLIENT_ID,CLIENT_REDIRECT_URL,CLIENT_SECRET,$_GET['code']);
        
        // Save the access token as a session variable
        $_SESSION['access_token'] = $data['access_token'];

        // Redirect to the page where user can create event
        header('Location: home.php');
        exit();
    }
    catch(Exception $e) {
        echo $e->getMessage();
        exit();
    }
}

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">

#logo {
    text-align: center;
    width: 200px;
    display: block;
    margin: 100px auto;
    border: 2px solid #2980b9;
    padding: 10px;
    background: none;
    color: #2980b9;
    cursor: pointer;
    text-decoration: none;
}

</style>
</head>

<body>

<?php

$login_url = 'https://accounts.google.com/o/oauth2/auth?scope=' . urlencode('https://www.googleapis.com/auth/calendar') . '&redirect_uri=' . urlencode(CLIENT_REDIRECT_URL) . '&response_type=code&client_id=' . CLIENT_ID . '&access_type=online';

?>

<a id="logo" href="<?= $login_url ?>">Login with Google</a>

</body>
</html>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...