刚刚完成了Google Reader上所有feed中图片自动下载脚本。
现在总结几点在网上找到不到tips:
1.to get all new item that in your google reader subscription
http://www.google.com/reader/api/0/stream/contents/user%2F{$user_id}%2Flabel%2FImages?ot={$last_month}&r=n&xt=user%2F{$user_id}%2Fstate%2Fcom.google%2Fread&n=500
ot: expire item timestamp
n: item numbers once request
*result is JSON format.
2.call google reader api to set "read" state which always getting 400 error from google.
to use POST method to fix 400 error.
POST URL: http://www.google.com/reader/api/0/edit-tag
POST FIELDS:a=user/{$user_id}/state/com.google/read&s={$feed}&i={$item_id}&T={$token}
现在我的小脚本正在疯狂下载中,哈哈哈哈哇。
iOS Developer
Showing posts with label api. Show all posts
Showing posts with label api. Show all posts
Tuesday, July 21, 2009
Saturday, July 18, 2009
to Get Google Reader Token codes
想写一个脚本把Google reader上我订阅的所有Feed里的图片抓下来(最近订了几个毛图站,哈哈)。看了Google Reader API,挺简单。但比较讨厌的是如果要设置一个read-listing里的item为已读,则要用到token。在网上找了一圈没有。。妈的,只好自己写。这个token不只是要Google登陆验证,有两个步骤,请看代码:
/* ------- start code ------- */
$authentication_url = 'https://www.google.com/accounts/ClientLogin';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $authentication_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "service=reader&Email=[your google account]&Passwd=[your pw]");
ob_start();
curl_exec($ch);
$sid = ob_get_clean();
curl_close($ch);
$cookie = preg_replace('/[\r\n]/','; ',$sid);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/reader/api/0/token');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
ob_start();
curl_exec($ch);
$token = ob_get_clean();
curl_close($ch);
echo $token //here you go baby.
/* ------- end code ------- */
Tags:
api,
authentication,
google,
reader
Subscribe to:
Posts (Atom)
