【问题标题】:PHP CURL Google Calendar using Private URL使用私有 URL 的 PHP CURL Google 日历
【发布时间】:2010-04-29 08:20:36
【问题描述】:

我正在尝试使用专用 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

【问题讨论】:

    标签: php curl google-calendar-api


    【解决方案1】:

    您可以“推出自己的”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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-17
      • 1970-01-01
      • 2023-02-17
      • 1970-01-01
      • 2016-09-18
      • 2013-10-04
      • 2012-07-09
      相关资源
      最近更新 更多