我有一个名为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']);
}
?>
“die”永远不会运行,我收到500服务器错误。由于代码在查询字符串中,为什么$client->authenticate($_GET['code']);
失败?我试图从渲染中分离数据代码。
答案 0 :(得分:1)
我认为查询字符串中没有“代码”。重定向到TaskVis.php时,您的“代码”值会丢失,并且不会将其包含在重定向中。然后,在该文件中,您在这里调用tasks.php ...
$.get("tasks.php", function(data){
...所以如果有任何_GET值,它们将包含在调用中:
$.get("tasks.php?code=xxxx", function(data){
我也有兴趣了解500错误的本质。您是否尝试在Firebug中查看控制台时调用此方法?