2009-10-09 5 views
0

J'ai écrit cette fonction pour obtenir le nombre non lu d'éléments google reader.Google Reader non lu Nombre

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; 
} 

Les en-têtes quand ils sont produits se présentent comme suit:

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 

Il se trouve juste là et le chargement une fois terminé il n'y a aucune chaîne de réponse. Est-ce un problème avec les en-têtes ou le fsockopen?

Répondre

0

Essayez d'abord de simplifier l'URL que vous essayez d'obtenir (essayez google.com). Si cela renvoie une réponse, il peut y avoir un problème d'authentification.

+0

J'ai essayé toutes sortes de combinaisons, j'ai fini par utiliser cUrl – woody993

Questions connexes