如何解决我进入浏览器无法使用谷歌日历 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 举报,一经查实,本站将立刻删除。