Google 阅读器未读计数

发布于 2024-08-07 09:21:55 字数 1511 浏览 4 评论 0原文

我编写这个函数是为了获取谷歌阅读器项目的未读计数。

function GetUnread($sid)
{
    $url = "http://www.google.com/reader/api/0/unread-count?all=true&output=xml";
    $msg = urldecode($msg);
    $msg = stripslashes($msg);
    $msg = urlencode($msg);
    $url = $url . $msg;

    $purl = parse_url($url);
    $uri = $purl['scheme'] . "://" . $purl['host'] . $purl['path'] . "?" . $purl['query'];

    $cookie = "Name=SID;SID=" . $sid . ";Domain=.google.com;Path=/;Expires=16000000";

    $headers = array();
    array_push($headers, "GET " . $uri . " HTTP/1.0");
    array_push($headers, "Host: " . $purl['host']);
    array_push($headers, "Referer: " . $uri);
    array_push($headers, "Cookie: " . $cookie);
    array_push($headers, "");
    $headers = implode("\r\n", $headers);

    echo $headers;

    $conn = fsockopen($purl['host'], 80, $errno, $errstr, 30);
    if ($conn)
    {
        fputs($conn, $headers);
        $response = "";
        while (!feof($conn)) //Appears to loop indefinitely until feof's timeout(60)
        {
            $response .= fgets($conn, 128);
        }
        fclose($conn);
    }

    echo $response;
}

生成的标头看起来像这样:

GET http://www.google.com/reader/api/0/unread-count?all=true&output=xml HTTP/1.0
Host: www.google.com
Referer: http://www.google.com/reader/api/0/unread-count?all=true&output=xml
Cookie: Name=SID;SID=DQA...zA;Domain=.google.com;Path=/;Expires=16000000

它只是坐在那里,一旦加载完成,就没有响应字符串。这是标头或 fsockopen 的问题吗?

I wrote this function to get the unread count of google reader items.

function GetUnread($sid)
{
    $url = "http://www.google.com/reader/api/0/unread-count?all=true&output=xml";
    $msg = urldecode($msg);
    $msg = stripslashes($msg);
    $msg = urlencode($msg);
    $url = $url . $msg;

    $purl = parse_url($url);
    $uri = $purl['scheme'] . "://" . $purl['host'] . $purl['path'] . "?" . $purl['query'];

    $cookie = "Name=SID;SID=" . $sid . ";Domain=.google.com;Path=/;Expires=16000000";

    $headers = array();
    array_push($headers, "GET " . $uri . " HTTP/1.0");
    array_push($headers, "Host: " . $purl['host']);
    array_push($headers, "Referer: " . $uri);
    array_push($headers, "Cookie: " . $cookie);
    array_push($headers, "");
    $headers = implode("\r\n", $headers);

    echo $headers;

    $conn = fsockopen($purl['host'], 80, $errno, $errstr, 30);
    if ($conn)
    {
        fputs($conn, $headers);
        $response = "";
        while (!feof($conn)) //Appears to loop indefinitely until feof's timeout(60)
        {
            $response .= fgets($conn, 128);
        }
        fclose($conn);
    }

    echo $response;
}

The headers when produced look like this:

GET http://www.google.com/reader/api/0/unread-count?all=true&output=xml HTTP/1.0
Host: www.google.com
Referer: http://www.google.com/reader/api/0/unread-count?all=true&output=xml
Cookie: Name=SID;SID=DQA...zA;Domain=.google.com;Path=/;Expires=16000000

It just sits there and once finished loading there is no response string. Is it an issue with the headers or the fsockopen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单调的奢华 2024-08-14 09:21:55

首先尝试简化您要获取的网址(只需尝试 google.com)。如果返回响应,则可能存在某种身份验证问题。

Firstly try simplifying the url you're trying to get (just try google.com). If that returns a response there's a chance there could be some sort of authentication issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文