Hello, friends.
I'm working on calendar app for the first time, so I'm new with
calendar API.
I've been looking for a while in this forum, but I was able to find
the solution to my problem.
I'm working with curl/php to retrieve the all calendar metafeed.
I encountered the "302 redirect", and I used CURLOPT_FOLLOWLOCATION to
redirect the request.
It works fine: I get the token and the output is OK.
But on page refresh I loose the session token and I get the following
message:
Token invalid - Invalid AuthSub token.
Error 401
Can anybody help me? Here is the code:
$next = urlencode("http://{$_SERVER['HTTP_HOST']}{$_SERVER
['PHP_SELF']}");
$scope = urlencode('http://www.google.com/calendar/feeds/');
$secure = false;
$session = true;
$token = $_GET['token']);
if(!$token) {
echo "<a href=\"https://www.google.com/accounts/AuthSubRequest?scope=
$scope&session=$session&secure=$secure&next=$next\">login to your
Google account</a>";
exit;
}
$session_token = exchangeToken($token);
echo "single use token = $token";
echo "<br />";
echo "session token = $session_token<br><br>";
$uri = "http://www.google.com/calendar/feeds/default/allcalendars/
full";
$result = getFeed($uri, $session_token);
$xml = simplexml_load_string($result);
echo "<br>ID: ".$xml->id;
echo "<br>title: ".$xml->title;
echo "<br>authorname: ".$xml->author->name;
echo "<br>email: ".$xml->author->email;
function getFeed($uri, $session_token){
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/atom+xml',
'Authorization: AuthSub token="' . trim($session_token) . '"'
));
$result = curl_exec($ch);
if (!$result) {
$result = curl_error($curl);
}
curl_close($ch);
return $result;
}
function exchangeToken($single_use_token) {
$ch = curl_init("https://www.google.com/accounts/
AuthSubSessionToken");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$str = array(
'Authorization: AuthSub token="' . trim($single_use_token) . '"'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $str);
$result = curl_exec($ch);
curl_close($ch);
$splitStr = split("=", $result);
return trim($splitStr[1]);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---