Google 阅读器未读计数
我编写这个函数是为了获取谷歌阅读器项目的未读计数。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先尝试简化您要获取的网址(只需尝试 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.