| 1 | <?php
|
| 2 | require_once __DIR__ . '/config.php';
|
| 3 |
|
| 4 | // First, login
|
| 5 | $cLogin = curl_init($base . 'api/greader.php/accounts/ClientLogin?Email=' . $user . '&Passwd=' . $pass);
|
| 6 | curl_setopt($cLogin, CURLOPT_SSL_VERIFYHOST, 0);
|
| 7 | curl_setopt($cLogin, CURLOPT_SSL_VERIFYPEER, 0);
|
| 8 | curl_setopt($cLogin, CURLOPT_RETURNTRANSFER, true);
|
| 9 | $keys = curl_exec($cLogin);
|
| 10 | curl_close($cLogin);
|
| 11 |
|
| 12 | // Then we fetch our feed (max 1000 elements) excluding those marked as read
|
| 13 | $ch = curl_init($base . 'api/greader.php/reader/api/0/stream/contents/reading-list?n=1000&xt=user/-/state/com.google/read');
|
| 14 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
| 15 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
| 16 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
| 17 | curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
| 18 | 'Authorization:GoogleLogin ' . str_replace('Auth=','auth=', explode("\n", $keys)[2])
|
| 19 | ));
|
| 20 | $out = curl_exec($ch);
|
| 21 | $json = json_decode($out);
|
| 22 | curl_close($ch);
|
| 23 |
|
| 24 | // We'll now go thru the results
|
| 25 | $out = [];
|
| 26 | foreach ($json->items as $item) {
|
| 27 | // If the source matches the exclude list, ignore
|
| 28 | if (in_array($item->origin->title, $exclude)) continue;
|
| 29 | // If it has a Newsletters label, ignore
|
| 30 | if (in_array('user/-/label/Newsletters', $item->categories)) continue;
|
| 31 |
|
| 32 | $u = $item->alternate[0]->href;
|
| 33 | $out[] = array(
|
| 34 | 'id' => $item->id,
|
| 35 | 'title' => $item->title,
|
| 36 | 'source' => $item->origin->title,
|
| 37 | 'link' => empty($u) ? $base . 'i/' : $u
|
| 38 | );
|
| 39 | }
|
| 40 |
|
| 41 | // And we save the results as json
|
| 42 | file_put_contents('public/rss.json', json_encode($out));
|