1

我正在尝试使用私有 URL 从 Google 日历中获取一系列事件。我阅读了 Google API 文档,但我想尝试在不使用 ZEND 库的情况下执行此操作,因为我不知道最终的服务器文件结构是什么,并且避免让其他人编辑代码。

我在发布之前也进行了搜索,遇到了相同的情况,即 PHP CURL_EXEC 使用 URL 返回 false,但如果使用 Web 浏览器打开 URL,我会得到一个 JSON 文件。由于我使用的是私有 URL,我真的需要使用 ZEND 对 Google 服务器进行身份验证吗?我试图让 PHP 在为 Flash 编码之前清理数组。

$URL = <string of the private URL from Google Calendar>
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($ch);
curl_close($ch);

$result = json_decode($data);

print '<pre>'.var_export($data,1).'</pre>';
Screen output >>> false
4

1 回答 1

2

您可以“推出自己的”AuthSub 或 oAuth 实现:

以下内容摘自: http ://code.google.com/apis/calendar/data/2.0/developers_guide_protocol.html#Auth

要为给定用户获取 AuthSub 令牌,您的应用程序必须将用户重定向到 AuthSubRequest URL,这会提示他们登录到他们的 Google 帐户。AuthSubRequest URL 可能如下所示:

https://www.google.com/accounts/AuthSubRequest?scope=http%3A%2F%2Fwww.google.com%2fcalendar%2Ffeeds%2F&session=1&secure=0&next=http%3A%2F%2Fwww.coolcalendarsite.com% 2Fwelcome.html

然后这样做...

GET /accounts/AuthSubSessionToken HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: AuthSub token="yourAuthToken"
User-Agent: Java/1.5.0_06
Host: https://www.google.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

然后这样做...

GET /calendar/feeds/default/private/full HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: AuthSub token="yourSessionToken"
User-Agent: Java/1.5.0_06
Host: www.google.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

更多关于 AuthSub 的文档:

http://code.google.com/apis/accounts/docs/AuthSub.html

于 2010-04-29T00:20:36.113 回答