I'm currently using the NYT News API to search for articles. I'm trying to get the Article Name, and URL from the JSON. How do I do this for each entry in the JSON?
$curl = curl_init();
$call = 'http://api.nytimes.com/svc/search/v2/articlesearch.json? q=Denmark&begin_date=20040112&end_date=20041212&sort=oldest&api-key=mykey';
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $call,
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
// Send the request & save response to $resp
echo $resp = curl_exec($curl);
curl_close($curl);
//Decode Json
$y = json_decode($resp,true);
It returns a large JSON, I'm interested in retrieving the weburl, and headline field. I've tried:
$url = $y['response']['docs']['web_url']
and
$headline = $y['response']['docs']['headline']
but with no success. Any thoughts?
I also need all the entries that have a web_url and headline in the JSON.
A single article entry from the JSON response:
{
"response": {
"meta": {
"hits": 291,
"time": 102,
"offset": 0
},
"docs": [{
"web_url": "http://www.nytimes.com/2005/01/14/arts/design/14anti.html",
"snippet": "On Wednesday, Christie's New York is having what it claims is the first-ever auction devoted solely to Georg Jensen silver, with some 800 objects.",
"lead_paragraph": "Georg Jensen silver from Denmark has a tactile quality all its own, probably because it is handmade. It gets only better with age. Michael von Essen, the founder and curator of the Georg Jensen Museum in Copenhagen, tried to explain its appeal: ''Once you have touched pieces of Jensen, you want to have them. The silver has a warmth to it, whether the style is 1900, Art Deco or modern.'' Last year, the company Georg Jensen founded celebrated its 100th anniversary. Jensen, who was not a gifted businessman, would probably have been surprised.",
"abstract": "Wendy Moonan Antiques column profiles Danish silversmith Georg Jensen, whose company celebrated its centennial last year; Michael von Essen, founder and curator of Georg Jensen Museum in Copenhagen, is giving talk about Jensen at Christie's, comments; photo (M)",
"print_page": "41",
"blog": [],
"source": "The New York Times",
"multimedia": [],
"headline": {
"main": "From Denmark, Moonlight's Glow",
"kicker": "Antiques"
},
"keywords": [{
"name": "persons",
"value": "JENSEN, GEORG"
}, {
"name": "persons",
"value": "VON ESSEN, MICHAEL"
}, {
"name": "organizations",
"value": "CHRISTIE'S"
}, {
"name": "subject",
"value": "JEWELS AND JEWELRY"
}, {
"name": "subject",
"value": "ANTIQUES"
}, {
"name": "subject",
"value": "AUCTIONS"
}, {
"name": "subject",
"value": "ART"
}, {
"name": "subject",
"value": "SILVER"
}],
"pub_date": "2005-01-14T00:00:00Z",
"document_type": "article",
"news_desk": "Leisure/Weekend Desk",
"section_name": "Arts",
"subsection_name": null,
"byline": {
"person": [{
"organization": "",
"role": "reported",
"rank": 1,
"firstname": "Wendy",
"lastname": "Moonan"
}],
"original": "By Wendy Moonan"
},
"type_of_material": "News",
"_id": "4fd2a5708eb7c8105d88d3af",
"word_count": 1152,
"slideshow_credits": null
}]
},
"status": "OK",
"copyright": "Copyright (c) 2013 The New York Times Company. All Rights Reserved."
}