<?php
if(isset($_GET['token']))
{
$url="http://www.google.com/calendar/feeds/default/allcalendars/full";
$useragent="PHP 5.2";
$header=array( "GET /accounts/AuthSubSessionToken HTTP/1.1",
"Content-Type: application/x-www-form-urlencoded",
"Authorization: AuthSub token=".$_GET['token'],
"User-Agent: PHP/5.2",
"Host: https://www.google.com",
"Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2",
"Connection: keep-alive"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
print_r($data);
}
?>
結果是找不到頁面。但是,我從firefox調用http://www.google.com/calendar/feeds/default/allcalendars/full,它是返回XML文件。所以,我認爲,我的代碼可能是錯誤的。但我找不到錯誤。 :(使用Google日曆的PHP捲曲
$ _GET [「令牌」] - 它是授權令牌或會話令牌?據我所知,你應該首先請求/帳戶/ AuthSubSessionToken返回一個頭中的會話令牌。然後在所有後續請求中使用該會話令牌。 – Kniganapolke 2010-01-19 09:38:01
嘗試刪除Host標頭,但無論如何它應該被忽略,因爲絕對網址。 – Kniganapolke 2010-01-19 09:58:51
來自https://www.google.com/accounts/AuthSubRequest?scope=http%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2F&session=1&secure=1&next=http%3A%2F%2Fmydomain.com – saturngod 2010-01-19 14:59:34