Created
April 27, 2015 12:46
-
-
Save Jacketbg/5deb42ec02b82bc0b91d to your computer and use it in GitHub Desktop.
Fetch your Inoreader starred articles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
This script exports user's starred articles via the official Inoreader API. | |
Use it in case you have thousands of starred articles since Inoreader's export function will not export much more than 1000 articles. | |
Use your Inoreader email and password to sign in. | |
You will need to create a developer application first to obtain $app_id and $app_key. Read here about this - http://www.inoreader.com/developers/register-app | |
*/ | |
$email = ""; // You Inoreader username or email | |
$password = ""; // Your Inoreader password | |
$app_id = ""; // Read here http://www.inoreader.com/developers/register-app | |
$app_key = ""; // Read here http://www.inoreader.com/developers/register-app | |
$max_iterations = 100; // Maximum number of iterations (paginations) to perform | |
$max_articles_per_iteration = 1000; // Don't go beyond 100. $max_iterations * $max_articles_per_iteration = maximum number of articles to be exported. | |
// End of configuration. Do not edit below. | |
$login_endpoint = "https://www.inoreader.com/accounts/ClientLogin"; | |
$api_endpoint = "https://www.inoreader.com/reader/api/0"; | |
$headers = array(); | |
$headers[] = "AppId: ".$app_id; | |
$headers[] = "AppKey: ".$app_key; | |
function http_send($url,$header=false,$post=false,$timeout=10){ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_USERAGENT, $ua); | |
curl_setopt($ch, CURLOPT_URL,$url); | |
curl_setopt($ch, CURLOPT_FAILONERROR, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); | |
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); | |
if($post){ | |
curl_setopt($ch, CURLOPT_POST,1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); | |
} | |
if($header){ | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
} | |
$response = curl_exec($ch); | |
curl_close($ch); | |
return $response; | |
} | |
$login = http_send($login_endpoint,$headers,"Email=".$email."&Passwd=".$password); | |
if(!$login){ | |
die("Wrong credentials!"); | |
} | |
preg_match("/Auth\=(.*?)$/", $login,$matches); | |
if(!$matches[1]){ | |
die("Cannot get auth token! Probably wrong credentials."); | |
} | |
// Add the Auth token for the next requests | |
$headers[] = "Authorization: GoogleLogin auth=".$matches[1]; | |
for($i=1;$i<=$max_iterations;$i++){ | |
$url = $api_endpoint."/stream/contents/user/-/state/com.google/starred?output=json&n=".$max_articles_per_iteration; | |
if($cont){ | |
$url .= "&c=".$cont; | |
} | |
$result = http_send($url,$headers,false,60); | |
if($result){ | |
$filename = "starred-".$i.".json"; | |
if(file_put_contents($filename, $result)){ | |
echo "Wrote ".strlen($result)." bytes to ".$filename."...\n"; | |
} | |
$matches = array(); | |
preg_match('/\"continuation\"\:\"(.*?)\"/', $result,$matches); // Much faster than json_decode! | |
if($matches[1]){ | |
$cont = $matches[1]; | |
}else{ | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment