0
我有一個名爲TasksLogin.php文件,它讓我登錄谷歌任務API認證不工作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']);
失敗?我試圖從渲染中分離出數據代碼。