首页 文章

如何在不将日历公开的情况下将Google日历嵌入外部网站时对用户进行身份验证

提问于
浏览
0

我正在寻找验证用户身份的最佳方式,并允许他访问嵌入在外部网站中的Google日历;我无法与世界分享日历,因为它包含私人活动 . 我的解决方案是使用相同的身份验证来使用Google API(请参阅下面的代码);一旦用户登录Google帐户(部分身份验证)并接受权限,他基本上就会登录Google,他可以在Google日历中看到(私人)事件 .

有没有更好的方法让用户访问嵌入式Google日历(不与世界共享日历)?

我的代码:

<?php
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_CalendarService.php';
session_start();

$client = new Google_Client();
$client->setApplicationName("Calendar Project");

$client->setClientId('XXXX');
$client->setClientSecret('XXX');
$client->setRedirectUri('XXX');
$client->setDeveloperKey('XXX');
$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])) 
{
  unset($_SESSION['token']);
}

if (isset($_GET['code'])) 
{
  $client->authenticate($_GET['code']);
  $_SESSION['token'] = $client->getAccessToken();
  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}

if (isset($_SESSION['token'])) 
{
  $client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()) {
    ?><iframe src="https://www.google.com/calendar/embed?src=emailhere%40gmail.com&ctz=America/Los_Angeles" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe><?php
$_SESSION['token'] = $client->getAccessToken();
} else {
  $authUrl = $client->createAuthUrl();
  print "Access the calendar <a class='login' href='$authUrl'>here</a>";
}
?>

谢谢!

1 回答

  • 0

    是的...您必须使用少量GMail帐户进行共享访问,以便他们可以登录并查看日历 . 此选项在日历设置下可用 .

相关问题