2009-10-09 72 views
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的问题?

回答

0

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

+0

我尝试了各种各样的组合,我已经结束了使用cUrl – woody993 2009-10-10 05:52:11