我有一个名为 TasksLogin.php 的文件,可以让我登录
session_start();
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_TasksService.php';
$client = new Google_Client();
$client->setClientId('xxxxx.apps.googleusercontent.com');
$client->setClientSecret('xxxxxxxxx');
$client->setRedirectUri('http://xxxxxxxxx/Tasks/TaskVis.html');
$client->setApplicationName("TasksForMike");
$tasksService = new Google_TasksService($client);
if (isset($_REQUEST['logout'])) {
unset($_SESSION['token']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
} else {
$client->setAccessToken($client->authenticate($_GET['code']));
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_GET['code'])) {
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
?>
<?php $_SESSION['token'] = $client->getAccessToken(); ?>
这似乎有效,因为它重定向到 TaskVis.php 但在 TasksVis.php 我调用:
$(document).ready(function() {
$.get("tasks.php", function(data){
var json = data;
});
});
这是获取任务并将它们打包在 json 对象中的 php 文件。但是在tasks.php中,我有这个崩溃的代码:
session_start();
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_TasksService.php';
$client = new Google_Client();
$client->setClientId('xxxxxx.apps.googleusercontent.com');
$client->setClientSecret('xxxxxxxxxxxxxxx');
$client->setRedirectUri('http://xxxxxxxxx/Tasks/TaskVis.html');
$client->setApplicationName("TasksForMike");
$tasksService = new Google_TasksService($client);
if (isset($_REQUEST['logout']))
{
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
echo "hh";
die();
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
?>
“死”永远不会运行,我得到一个 500 服务器错误。由于代码在查询字符串中,为什么$client->authenticate($_GET['code']);
失败?我正在尝试将数据代码与渲染分开。