I decided to dig into the guide Content from an API | Kirby CMS, but it’s become outdated, as the NYT movie review API has been shut down. They suggest an alternate way to access movie reviews, but I can’t quite get it to work.
That may be enough info right there — but FWIW, here’s what I’ve tried:
Per the NYT Article Search | Dev Portal, I edited the request on line 16 of models/reviews.php :
$request = Remote::get('https://api.nytimes.com/svc/search/v2/articlesearch.json?fq=section_name%3A"Movies"&type_of_material%3A"Review"&sort=newest&page=0&api-key=' . $apiKey);
(The request string alone does work in the browser and returns movie article data, though it doesn’t appear limited to reviews.)
I further edited some of the query fields to what’s available per the raw JSON returns and the list at Article Search | Dev Portal:
foreach ($results as $key => $review) {
$pages[] = [
'slug' => Str::slug($review->headline), /* changed from 'display_title' */
'num' => $key+1,
'template' => 'review',
'model' => 'review',
'content' => [
/* 'title' => $review->display_title, -- not available */
'headline' => $review->headline->main,
'byline' => $review->byline->original,
'lead_paragraph' => $review->summary_short, /* changed from 'summary' */
'pub_date' => $review->publication_date, /* changed from 'date' */
'web_url' => $review->link->url, /* changed from 'link' */
'snippet' => $review->link->suggested_link_text, /* changed from `linkText` */
'cover' => $review->multimedia->2->url,
'uuid' => Uuid::generate(),
]
];
}
This got me the error:
Undefined property: stdClass::$results
The results seem(?) to be called “response” now, so I tried editing line 18 of models/reviews.php:
if ($request->code() === 200) {
$results = $request->json(false)->response; /* changed to response from results */
}
This gets farther, but no matter what I do I get some variety of the error:
Attempt to read property "headline" on array
And that’s where I run out of obvious ideas. If I’m missing something simple, a hint would be appreciated so I can continue, but the Guide article should probably get a refresh…