我有一个在服务器上运行的 cron 作业,当我通过 ssh 进入服务器和文件夹时,我可以毫无问题地运行脚本。但是,当 cron 作业运行时,它正在寻找令牌。有没有办法做到这一点?
function checkCalendar()
{
$logFile = openLogFile("_Subscription.log");
$client = getClient();
$service = new Google_Service_Calendar($client);
$calendarId = 'XXXX_CALENDAR_XXXX@group.calendar.google.com'; // Testing Calendat
date_default_timezone_set("America/Los_Angeles");//set timezone America/Lima
$today = date("m-d-Y");
$startofday = date("Y-m-d") . "T00:00:00-08:00";
$endofday = date("Y-m-d") . "T23:59:59-08:00";
$optParams = array('timeMax' => $endofday,
'timeMin' => $startofday);
$events = $service->events->listEvents($calendarId, $optParams);
writeLogMessage($logFile, "Subscriptions for {$today}\n");
while(true) {
foreach ($events->getItems() as $event) {
writeLogMessage($logFile, "Customer -> " . $event->getSummary() . "\n");
writeLogMessage($logFile, "DATA -> " . $event->getDescription() . "\n");
}
$pageToken = $events->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$events = $service->events->listEvents($calendarId, $optParams);
} else {
break;
}
}
closeLogFile($logFile);
return("200");
}
$calendarId
是从这篇文章中删除的正确 ID。
这里是错误:
Open the following link in your browser:
accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&client_id=327785147494-fnorqnq2f8f2dejsrllf9dv6v4220sff.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&state&scope=https://www.googleapis.com/auth/calendar&prompt=select_account consent
Enter verification code:
Fatal error: Uncaught InvalidArgumentException: Invalid code in /home/customer/www/xxx-consulting.com/public_html/PPLG/includes/google/vendor/google/apiclient/src/Client.php:239
Stack trace:
#0 /home/customer/www/xxx-consulting.com/public_html/PPLG/includes/googleCalendar.php(47): Google\Client->fetchAccessTokenWithAuthCode('')
#1 /home/customer/www/xxx-consulting.com/public_html/PPLG/includes/googleCalendar.php(104): getClient()
#2 /home/customer/www/xxx-consulting.com/public_html/PPLG/cron/CalendarRead.php(10): checkCalendar()
#3 {main}
thrown in /home/customer/www/xxx-consulting.com/public_html/PPLG/includes/google/vendor/google/apiclient/src/Client.php on line 239