This PHP CURL example uses cookies, POST, and SSL options to login to Google Reader and fetch the number of subscribers for a feed.
Note: If you don't have a Google Reader account you need to get one for this script to function.
]*?>.*?@si','@@si','@@siU','@<![sS]*?--[ tnr]*>@'); $g=preg_replace($s, '', $askapache_curl_google_result); $g=preg_match('@href="([^"]*?)"@si',$g,$m); $ch = curl_init($m[1]); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $google_cookie); curl_setopt ($ch, CURLOPT_COOKIEFILE, $google_cookie); $askapache_curl_google_result = curl_exec ($ch); curl_close($ch); $g=preg_match('@href="([^"]*?)"@si',$askapache_curl_google_result,$j); $ch = curl_init("http://www.google.com/reader/directory/search?q=$feedurl"); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $google_cookie); curl_setopt ($ch, CURLOPT_COOKIEFILE, $google_cookie); $askapache_curl_google_result = curl_exec ($ch); curl_close($ch); $y=preg_match('@class="feed-result-stats">([^<]*?)@si',$askapache_curl_google_result,$s); // output results header("Content-type: text/plain"); echo "(".$s[1].") Subscribers for feed: ".urldecode($feedurl); // delete cookie file unlink($google_cookie); exit 0; exit; /* "Google AdSense Automatic Login with PHP and CURL" https://www.askapache.com/webmaster/login-to-google-adsense-using-php/ "Follow your Adsense earnings with an RSS reader" http://curl.askapache.com/libcurl/php/examples/rss-adsense.html "Auto-Login to Google Analytics to impress Clients"*/ ?> Auto-Login to Google Analytics to impress Clients
Thanks Google, You Rock!
Google Reader reports subscriber counts when we crawl feeds (within the "
User-Agent:
" header in HTTP). Currently, these counts include users of both Google Reader and iGoogle, and over time will include subscriptions from other Google properties.The "
User-Agent:
" header of our crawler includes the name of our crawler ("FeedFetcher-Google") along with its associated URL, the subscriber count, and a unique 64-bit feed identifier ("feed-id"). You might see multiple requests for the same feed with distinct "feed-id" values. This happens if the same feed is referenced through multiple URLs (for example, because of redirects). In that case, you'll need to sum up the subscribers to a feed that have distinct "feed-id" values to determine the total number of Google subscribers to the feed.Below is an example of the contents of the "
User-Agent:
" header:
User-Agent: Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; 4 subscribers; feed-id=1794595805790851116)