Authorization 谷歌日历API授权一直在询问

Authorization 谷歌日历API授权一直在询问,authorization,google-calendar-api,Authorization,Google Calendar Api,我的问题很简单,我正在使用带有php脚本的Google日历API 我的脚本正在运行,但我不能用cron运行它,因为我需要一直授权我的应用程序 有什么办法可以满足我的要求吗 这是我的密码: <?php require_once 'google/Google_Client.php'; require_once 'google/contrib/Google_CalendarService.php'; session_start(); $client = new Google_Client()

我的问题很简单,我正在使用带有php脚本的Google日历API

我的脚本正在运行,但我不能用cron运行它,因为我需要一直授权我的应用程序

有什么办法可以满足我的要求吗

这是我的密码:

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


$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");
$client->setClientId([MY APP ID]);
$client->setClientSecret([MY SECRET TOKEN]);
$client->setRedirectUri([MY REDIRECT URI]);
$client->setDeveloperKey([MY DEV KEY]);
$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])) {
  unset($_SESSION['token']);
}

/*
** Request token from API
*/
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()) {


  // MY CODE GOES HERE


  } else {

  $authUrl = $client->createAuthUrl();
  print "<a class='login' href='$authUrl'>Connect Me!</a>";
}


?>


谢谢

我不知道你是否有这个问题的答案,但我曾经有过同样的问题。GoogleAPI返回Oauth访问令牌。此令牌无限期地持续,但在代码中,您将其存储在$\u SESSION变量中,该变量有一个它将保持的时间跨度。尝试使用
$token=$client->getAccessToken()
以便将访问令牌放入变量中,然后以其他形式存储令牌,例如数据库。然后,当检查是否设置了
$\u会话['token']
时,如果未设置,则可以查询数据库以检索该令牌并使用
$client->setAccessToken($queryResult)只要您拥有该访问令牌,API就会处理其余部分