Publishing Drupal content via the Apple News API

News, Apple’s all new app available with iOS 9, delivers rich and immersive news, magazine, and web content to millions of users. With Apple News Format, publishers can create signature content for News with custom typography, rich photo galleries, video, and fun animations. Content is automatically optimized for both iPhone and iPad and publishers can earn revenue with iAd, Apple’s advertising platform.

The Apple News API makes it easy to connect to your existing content management system, giving you control over how your Drupal content is rendered in News, including placement of elements, background fills — as well as effects such as parallax and element transitions as the reader interacts with and scrolls through your content.

Apple News Format is coming soon

Sign up as a publisher and get notified when Apple News Format becomes available.

Our Drupal Apple News Integration module

Our Drupal Publish to Apple News module makes it easy for both novice and advanced Drupal administrators to publish content to the Apple News API. In addition to allowing you to convert Drupal content into Apple News Format, our module also allows you to use one of several templates that ship with the module — or create your own Apple News Format layouts, each of which is easily configurable for iAd advertising.

The big idea with our module is that it gives you the ability to utilize layouts to define how your content translates to Apple News Format via its API.

For example, if in a given Apple News Format template, you have components for a hero image, a title, a body, and a gallery, you can define where the content for these components should come from on the Drupal side when a given node of that content type is shipped off to News.

In this example, we might tie a given Apple News Format template to your “Basic Page” Drupal content type and define that the hero image in the Apple News Format template should pull from the default image field. In addition, the template body and title should come from the node body and title respectively. Lastly, we can define that the template gallery content should come from a new multi-value image field in the content type that we’ve added to the content type for just this purpose.

Admittedly, this is a bit of an abstract concept (having a “middle” layer between your Drupal content and the Apple News API), but with this abstraction comes tremendous power. It means that when Drupal content is added or updated, our module can transform the content for that node into a format that the Apple News API can understand using the mapping you’ve defined in the template. The end result is that your content renders in News where and how you wish without any effort on your behalf after the initial (very fast) setup.

For more advanced Drupal users too

For developers who want practical Drupal examples of how to push content to the Apple News API, you can use the Apple News API library included in the library folder of the module for your own custom php or Drupal applications. It provides methods for most of the Apple News API calls, including authentication and article POST, as well as section, channel, and article GET.

You can also look at how we integrated the Apple News API with content types to create your own custom configurations with Views, Panels, and Blocks for Drupal content that doesn’t live purely within a node.

A quick walk-through in seven simple steps

Below is a quick tutorial on how to get your Drupal content into News within minimal configuration. We will cover more advanced News Components such as galleries (which can easily be configured using Field Collections) in a future blog post.

Step 1: First, sign up to deliver your content to News. Register with News Publisher, set up your News channel and obtain your Apple News API credentials. More information can be found at https://developer.apple.com/news-publisher.

Step 2: Install and enable the Drupal module

Step 3: Under the Configuration admin menu, select “Apple News Settings” to configure your Apple News API key, Apple News shared secret, Default channel ID, Default section ID, and Article identifier (configured using Drupal tokens).

Step 4: Under Structure in the Drupal main admin menu, select: Apple News Article Types -> Create Article Type from Template

Step 5: Choose the content type you want to map to News, as well as the Apple News Format template you’d like to start with.

Step 6: Map each of the fields within the selected content type to the Apple News Format template using Drupal tokens. By performing this “mapping”, you are telling our module where to “place” each of the elements of the nodes from this content type when your content is sent to the Apple News API on node create or update.

In my example, I’ll map the fields from the Simple Center Aligned Article in this way:

  • Background Image: [node:field_image]
  • Author: [node:author:name]
  • Body: [node:body]

I’ll check the box for “Include an advertisement?” because I would like ads to show up within my content when it is viewed on News. Note that you will first need to enable iAd advertising in News Publisher before you can start earning revenue. More information can be found at https://developer.apple.com/news-publisher.

Step 7: Click “Create” and that’s it! Your Drupal content for that content type will automatically flow through to News on node save or update for all published nodes.

A few notes worth mentioning

You should note that if you’re having a hard time figuring out which tokens to use with your content, you can find a complete listing by clicking the “Replacement Patterns” helper link below each field.

You can edit delete, and configure new templates by clicking on Structure->Apple News Article Types in the admin menu.

You can also bulk publish or remove content from News through the default Content Administration interface by selecting the content in question and performing the “Publish selected content to Apple News” or “Remove selected content from Apple News” from the “Update Options” dropdown.

Need help getting set up?

If you need help setting up or configuring your site for News or mapping more advanced News components to your Drupal content, feel free to reach out and consult our team of Drupal experts. We’re happy to help!

A bit about Casey:

Casey Cobb (Partner, Senior Software Engineer) has over 15 years of experience in web and software development. He has a B.S. in Computer Science and his specialties include Open Source web development (most notably Drupal), custom PHP, MySQL, jQuery, Zend Framework, mobile development, as well as project architecture and project management.