_validateUser($username, $password)) { $this->_username = $username; $this->_password = $password; $this->loaded = true; $this->_connect(); } else { $this->loaded = false; } } private function _connect() { $this->_getToken(); return $this->_token != null; } private function _getToken() { $this->_getSID(); $this->_cookie = "SID=" . $this->_sid . "; domain=.google.com; path=/"; $url = "http://www.google.com/reader/api/0/token"; $ch = curl_init(); // curl_setopt($ch, CURLOPT_COOKIE, $this->_cookie); // This was the old authentication method curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded', 'Authorization: GoogleLogin auth=' . $this->_auth)); // This, apparently, is the new one. curl_setopt($ch, CURLOPT_URL, $url); ob_start(); curl_exec($ch); curl_close($ch); $this->_token = ob_get_contents(); ob_end_clean(); } private function _getSID() { $requestUrl = "https://www.google.com/accounts/ClientLogin?service=reader&Email=" . urlencode($this->_username) . '&Passwd=' . urlencode($this->_password); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $requestUrl); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); ob_start(); curl_exec($ch); curl_close($ch); $data = ob_get_contents(); ob_end_clean(); $sidIndex = strpos($data, "SID=")+4; $lsidIndex = strpos($data, "LSID=")-5; $authIndex = strpos($data, "Auth=")+5; $this->_sid = substr($data, $sidIndex, $lsidIndex); $this->_auth = substr($data, $authIndex, strlen($data)); } private function _validateUser($user, $pass) { $requestUrl = "https://www.google.com/accounts/ClientLogin?service=reader&Email=" . urlencode($user) . '&Passwd=' . urlencode($pass); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $requestUrl); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); ob_start(); curl_exec($ch); curl_close($ch); $data = ob_get_contents(); ob_end_clean(); if(trim($data) == 'Error=BadAuthentication') { return false; } else { return true; } } private function _httpGet($requestUrl, $getArgs) { $url = sprintf('%1$s?%2$s', $requestUrl, $getArgs); $https = strpos($requestUrl, "https://"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); if($https === true) curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); // curl_setopt($ch, CURLOPT_COOKIE, $this->_cookie); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded', 'Authorization: GoogleLogin auth=' . $this->_auth)); ob_start(); try { curl_exec($ch); curl_close($ch); $data = ob_get_contents(); ob_end_clean(); } catch(Exception $err) { $data = null; } return $data; } private function _httpPost($requestUrl, $fields) { $https = strpos($requestUrl, "https://"); foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$requestUrl); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); if($https === true) curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); // curl_setopt($ch, CURLOPT_COOKIE, $this->_cookie); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded', 'Authorization: GoogleLogin auth=' . $this->_auth)); try { $result = curl_exec($ch); curl_close($ch); return $result; } catch(Exception $err) { return null; } } /* Public Methods */ // List all subscriptions public function listAll() { $gUrl = "http://www.google.com/reader/api/0/stream/contents/user/-/state/com.google/reading-list"; $args = sprintf('ck=%1$s', time()); return $this->_httpGet($gUrl, $args); } // List a particular number of unread posts from the user's reading list public function listUnread($limit) { $out = '