alleyinteractive / apple-news

The Publish to Apple News plugin enables your WordPress blog content to be published to your Apple News channel.
https://wordpress.org/plugins/publish-to-apple-news/
GNU General Public License v3.0
152 stars 70 forks source link

How To: Cron Job to Publish Articles #1143

Open timatron opened 4 days ago

timatron commented 4 days ago

Description

We are finding lots of errors with automatic publishing of articles to Apple News almost always we see this error: NOT_FOUND (keyPath articleId)

What is the best way to setup a cron job to publish any articles articles published within X timeframe? I found the apple_news_async_push hook, but its unclear how to prep articles to publish and publish them with this action.

Is there any documentation or guidance on this?

Thanks, Tim

kevinfodness commented 4 days ago

Async is deprecated and I don't advise that you use it.

If you're seeing NOT_FOUND that means that it's trying to update, not create, and the Apple News API is telling you that it can't find the article ID you're trying to update. If that's the case, then a cron job to publish articles isn't going to help you, because you'll get the same error.

For the posts that are failing, take a look in the postmeta table and see if there's an Apple News article ID, then try to find the corresponding ID in iCloud News Publisher - I bet it isn't there.

The most common way this situation occurs is when using a plugin to make a copy of a post, where it copies the postmeta in addition to the values in the posts table, and it makes a copy of the Apple News postmeta as well, including the article ID. If the article ID was deleted via iCloud News Publisher and not through WordPress, then the meta for the article ID would still be intact on the original post, and making a copy of that post and trying to publish it would result in the exact scenario you're describing. Maybe this was the case for a post that you're using as a template?