<?php
define('API_KEY', 'YOUR_API_KEY');
define('API_URL', 'http://api.nytimes.com/svc/search/v1');
$n = 10;
$i = 0;
do{
$start = $i * $n;
print "$start\n";
$params = array(
'api-key' => API_KEY,
'query' => 'des_facet:[SCIENCE AND TECHNOLOGY]',
'offset' => $i,
'fields' => 'byline,body,date,title,url,des_facet',
);
$data = json_decode(file_get_contents(API_URL . '/article?' . http_build_query($params)));
foreach ($data->results as $item)
file_put_contents(sprintf('articles/%s.js', md5($item->url)), json_encode($item));
sleep(1);
} while ($start total && ++$i
Sadly it doesn't seem possible to get the categories assigned to an individual article - adding "facets=des_facet" only provides the sum of the categories across the 10 results. (see comment below).
The same Nature News story as before has these similar articles:
- OBSERVATORY; Galaxies Made Simple, or at Least Less Complicated
- THE YEAR IN IDEAS; Dark Energy
- Q&A
- Galaxies Twice as Bright as They Seem, Study Finds
- Stars Suggest a Quark Twist And a New Kind of Matter
- OBSERVATORY; Galactic Puzzle Solved? Threads Tie It Together
- VAST 'HOLE' IN SPACE APPEARS TO DEFY THEORIES
- ESSAY; Computing, 2016: What Won't Be Possible?
- THE NOVEMBER REPORT; Scientists In Waiting
- A Puzzle Finally Makes the 'Cosmic Figures' Fit
and the 50 most similar articles have these categories:
- SPACE [17]
- PHYSICS [14]
- RESEARCH [6]
- STARS AND GALAXIES [6]
- UNIVERSE [6]
- REVIEWS [5]
- ASTRONOMY AND ASTROPHYSICS [5]
- BOOKS AND LITERATURE [4]
- HUBBLE SPACE TELESCOPE [4]
- COMPUTERS AND THE INTERNET [4]
- EDUCATION AND SCHOOLS [3]
- SOCIAL CONDITIONS AND TRENDS [3]
- TELESCOPES AND OBSERVATORIES [3]
- UNITED STATES ECONOMY [2]
- BIOGRAPHICAL INFORMATION [2]
- GENETICS AND HEREDITY [2]
- THIRD WORLD AND DEVELOPING COUNTRIES [2]
- PHOTOGRAPHY [2]
- ACCIDENTS AND SAFETY [2]