PHPackages                             tomgould/apple-news-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. tomgould/apple-news-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

tomgould/apple-news-api
=======================

Modern PHP client for the Apple News Publisher API with full Apple News Format document support

v2.0.2(1mo ago)1636—3.8%1MITPHPPHP ^8.1CI passing

Since Dec 20Pushed 1mo agoCompare

[ Source](https://github.com/tomgould/Apple-News-API)[ Packagist](https://packagist.org/packages/tomgould/apple-news-api)[ Docs](https://github.com/tomgould/apple-news-api)[ RSS](/packages/tomgould-apple-news-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (18)Versions (14)Used By (0)

Apple News API PHP Client
=========================

[](#apple-news-api-php-client)

A modern, PSR-compliant PHP library for the Apple News Publisher API with full Apple News Format (ANF) document support.

[![Latest Version](https://camo.githubusercontent.com/ce3941170f52a624085bfe87e3b9336a6980866d32d42c7824256509dce8533a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6d676f756c642f6170706c652d6e6577732d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tomgould/apple-news-api)[![Total Downloads](https://camo.githubusercontent.com/a845b2e9313a879116d9c38640b739907a716ad1d4858ac86d3cf8a549ab67ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f6d676f756c642f6170706c652d6e6577732d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tomgould/apple-news-api)[![CI](https://github.com/tomgould/apple-news-api/actions/workflows/ci.yml/badge.svg)](https://github.com/tomgould/apple-news-api/actions)[![PHP Version](https://camo.githubusercontent.com/5320e43ba12e2d980fa78e1a78b49449083e070e25835dd3a0735065b7e43775/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f6d676f756c642f6170706c652d6e6577732d6170692e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![License](https://camo.githubusercontent.com/db35ae70a111468f2e509f2852cfdff0323abdf7f9fefb3090188ac014019ee7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f6d676f756c642f6170706c652d6e6577732d6170692e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Features
--------

[](#features)

- 🚀 **Modern PHP 8.1+** with strict types and named arguments
- 🔌 **PSR-18 HTTP Client** compatible (works with Guzzle, Symfony, etc.)
- 📝 **Full Apple News Format** support with a fluent, object-oriented document builder
- 🎨 **Complete ANF Coverage** — 45+ components, animations, behaviors, scenes, and conditional styles
- 🔐 **HMAC-SHA256 Authentication** handled automatically
- 📦 **Zero Framework Dependencies** — use with any framework or standalone
- ✅ **Thoroughly Tested** — 99.9%+ code coverage

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- A PSR-18 HTTP client (e.g., Guzzle)
- Apple News Publisher API credentials

Installation
------------

[](#installation)

```
composer require tomgould/apple-news-api
```

You also need a PSR-18 HTTP client and PSR-17 factories. Guzzle is recommended:

```
composer require guzzlehttp/guzzle guzzlehttp/psr7
```

Quick Start
-----------

[](#quick-start)

```
use TomGould\AppleNews\Client\AppleNewsClient;
use TomGould\AppleNews\Document\Article;
use TomGould\AppleNews\Document\Components\{Title, Body, Photo};
use TomGould\AppleNews\Document\Metadata;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;

// 1. Create the client
$factory = new HttpFactory();
$client = AppleNewsClient::create(
    keyId: 'your-api-key-id',
    keySecret: 'your-api-secret',
    httpClient: new Client(),
    requestFactory: $factory,
    streamFactory: $factory
);

// 2. Build an article
$article = Article::create(
    identifier: 'my-article-123',
    title: 'Breaking News Story',
    language: 'en'
);

$article
    ->addComponent(new Title('Breaking News Story'))
    ->addComponent(Photo::fromUrl('https://example.com/hero.jpg'))
    ->addComponent(new Body('This is the article content...'));

$article->setMetadata(
    (new Metadata())
        ->addAuthor('Jane Doe')
        ->setExcerpt('A short summary of the article')
);

// 3. Publish to Apple News
$response = $client->createArticle('your-channel-id', $article);

echo "Published! Article ID: " . $response['data']['id'];
```

---

Full Implementation Guide
-------------------------

[](#full-implementation-guide)

### Getting Your API Credentials

[](#getting-your-api-credentials)

1. Sign up for [Apple News Publisher](https://developer.apple.com/apple-news/)
2. Create a channel for your publication
3. Generate API credentials (Key ID and Secret)

### Client Initialization

[](#client-initialization)

```
use TomGould\AppleNews\Client\AppleNewsClient;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;

$factory = new HttpFactory();
$httpClient = new Client();

$client = AppleNewsClient::create(
    keyId: 'your-key-id',
    keySecret: 'your-base64-secret',
    httpClient: $httpClient,
    requestFactory: $factory,
    streamFactory: $factory
);
```

### Building Articles

[](#building-articles)

#### Create the Article

[](#create-the-article)

```
use TomGould\AppleNews\Document\Article;

$article = Article::create(
    identifier: 'my-internal-id-123',
    title: 'The Future of Web Development',
    language: 'en',
    columns: 7,
    width: 1024
);
```

#### Add Metadata

[](#add-metadata)

```
use TomGould\AppleNews\Document\Metadata;

$metadata = (new Metadata())
    ->addAuthor('Jane Doe')
    ->setExcerpt('An in-depth look at modern web frameworks.')
    ->addKeywords(['PHP', 'Web', 'Programming'])
    ->setDatePublished(new DateTime())
    ->setContentGenerationType('none'); // AI disclosure

$article->setMetadata($metadata);
```

#### Define Reusable Styles

[](#define-reusable-styles)

```
use TomGould\AppleNews\Document\Styles\ComponentTextStyle;

$bodyStyle = (new ComponentTextStyle())
    ->setFontName('Helvetica')
    ->setFontSize(18)
    ->setLineHeight(24)
    ->setTextColor('#333333');

$article->addComponentTextStyle('defaultBody', $bodyStyle);
```

#### Add Components

[](#add-components)

```
use TomGould\AppleNews\Document\Components\{Title, Body, Photo, Heading, Divider};

$article
    ->addComponent(new Title('The Future of Web Development'))
    ->addComponent(new Divider())
    ->addComponent(new Heading('Introduction', level: 2))
    ->addComponent(
        (new Body('This is the main paragraph.'))
            ->setFormat('html')
            ->setTextStyle('defaultBody')
    );
```

### Available Components

[](#available-components)

#### Text Components

[](#text-components)

ComponentDescription`Title`Article title`Heading`Section headings (levels 1-6)`Body`Paragraph text`Intro`Introduction/lead paragraph`Caption`Image/video captions`Pullquote`Highlighted quotes`Quote`Block quotes`Byline`Author byline`Author`Author name`Illustrator`Illustrator credit`Photographer`Photographer credit#### Media Components

[](#media-components)

ComponentDescription`Photo`Single image`Figure`Image with caption`Portrait`Portrait-oriented image`Logo`Publication logo`Gallery`Image gallery`Mosaic`Mosaic image layout`Video`Native video`Audio`Audio player`Music`Apple Music integration`Podcast`Podcast embed`ARKit`AR Quick Look experiences#### Social Embeds

[](#social-embeds)

ComponentDescription`Tweet`Twitter/X embeds`Instagram`Instagram embeds`FacebookPost`Facebook embeds`TikTok`TikTok embeds`EmbedWebVideo`YouTube/Vimeo embeds#### Structure Components

[](#structure-components)

ComponentDescription`Container`Group components together`Section`Article section`Chapter`Chapter division`Header`Section header`Footer`Section footer`Aside`Sidebar content`Divider`Visual separator`FlexibleSpacer`Flexible spacing in horizontal stacks#### Data Components

[](#data-components)

ComponentDescription`DataTable`Data-driven table`HTMLTable`HTML-based table`Map`Interactive map`Place`Location marker#### Interactive Components

[](#interactive-components)

ComponentDescription`LinkButton`Call-to-action buttons`BannerAdvertisement`Banner ad placement`MediumRectangleAdvertisement`Medium rectangle ad`ReplicaAdvertisement`Print replica ad### Animations, Behaviors &amp; Scenes

[](#animations-behaviors--scenes)

#### Animations

[](#animations)

```
use TomGould\AppleNews\Document\Animations\{
    AppearAnimation,
    FadeInAnimation,
    MoveInAnimation,
    ScaleFadeAnimation
};

// Fade in animation
$component->setAnimation(FadeInAnimation::standard());

// Move in from left
$component->setAnimation(MoveInAnimation::fromLeft());

// Scale and fade
$component->setAnimation(ScaleFadeAnimation::subtle());
```

#### Behaviors

[](#behaviors)

```
use TomGould\AppleNews\Document\Behaviors\{
    Parallax,
    Springy,
    BackgroundParallax
};

// Parallax scrolling effect
$component->setBehavior(Parallax::withFactor(0.5));

// Spring physics
$component->setBehavior(Springy::create());

// Background parallax
$component->setBehavior(BackgroundParallax::withFactor(0.8));
```

#### Scenes (for Headers)

[](#scenes-for-headers)

```
use TomGould\AppleNews\Document\Scenes\{
    FadingStickyHeader,
    ParallaxScaleHeader
};

// Fading sticky header
$header->setScene(FadingStickyHeader::create());

// Parallax scale header
$header->setScene(ParallaxScaleHeader::create());
```

### Responsive Design with Conditions

[](#responsive-design-with-conditions)

```
use TomGould\AppleNews\Document\Layouts\Condition;
use TomGould\AppleNews\Document\Conditionals\{
    ConditionalComponentStyle,
    ConditionalTextStyle,
    ConditionalComponentLayout
};

// Dark mode styling
$darkStyle = ConditionalComponentStyle::darkMode('#1C1C1E');

// Compact width layout
$compactLayout = ConditionalComponentLayout::fullWidthOnCompact();

// Viewport-based conditions
$condition = Condition::viewportWidth(375, 768);

// Platform-specific
$iosCondition = Condition::iOS();
$macCondition = Condition::macOS();
```

### Fills and Backgrounds

[](#fills-and-backgrounds)

```
use TomGould\AppleNews\Document\Styles\Fills\{
    ImageFill,
    LinearGradientFill,
    VideoFill
};

// Image background
$fill = ImageFill::fromUrl('https://example.com/bg.jpg')->asCover();

// Gradient background
$gradient = LinearGradientFill::vertical('#000000', '#333333');

// Video background
$video = VideoFill::fromUrl('https://example.com/bg.mp4')->setLoop(true);
```

### Working with Assets

[](#working-with-assets)

#### Bundle Assets (Local Files)

[](#bundle-assets-local-files)

```
$article->addComponent(Photo::fromBundle('hero.jpg'));

// Provide the file path when publishing
$assets = [
    'bundle://hero.jpg' => '/path/to/hero.jpg'
];

$client->createArticle($channelId, $article, null, $assets);
```

#### Remote Assets

[](#remote-assets)

```
$article->addComponent(
    Photo::fromUrl('https://example.com/image.jpg')
);
```

### API Operations

[](#api-operations)

#### Channels

[](#channels)

```
$channel = $client->getChannel($channelId);
$quota = $client->getChannelQuota($channelId);
```

#### Sections

[](#sections)

```
$sections = $client->listSections($channelId);
$section = $client->getSection($sectionId);
$client->promoteArticles($sectionId, ['article-id-1', 'article-id-2']);
```

#### Articles

[](#articles)

```
use TomGould\AppleNews\Request\ArticleMetadata;
use TomGould\AppleNews\Enum\MaturityRating;

// Create with metadata
$metadata = (new ArticleMetadata())
    ->setIsSponsored(false)
    ->setIsCandidateToBeFeatured(true)
    ->setMaturityRating(MaturityRating::GENERAL)
    ->addTargetTerritories(['US', 'GB', 'CA']);

$response = $client->createArticle($channelId, $article, $metadata->toArray(), $assets);

// Read
$article = $client->getArticle($articleId);

// Search
$results = $client->searchArticlesInChannel($channelId, ['pageSize' => 20]);

// Update (requires revision token)
$client->updateArticle($articleId, $revision, $updatedArticle);

// Delete
$client->deleteArticle($articleId);
```

### Error Handling

[](#error-handling)

```
use TomGould\AppleNews\Exception\AppleNewsException;
use TomGould\AppleNews\Exception\AuthenticationException;

try {
    $client->createArticle($channelId, $article);
} catch (AuthenticationException $e) {
    // Invalid API credentials (401/403)
    echo "Auth failed: " . $e->getMessage();
} catch (AppleNewsException $e) {
    // Other API errors
    echo "Error: " . $e->getMessage();
    echo "Code: " . $e->getErrorCode();    // e.g., 'INVALID_DOCUMENT'
    echo "Field: " . $e->getKeyPath();      // e.g., 'components[0].text'
}
```

---

Generating Documentation
------------------------

[](#generating-documentation)

Generate a local API reference:

```
# First-time setup
mkdir -p tools
composer docs:install

# Generate HTML docs
composer docs

# Generate Markdown docs
composer docsmd
```

Open `docs/html/index.html` in your browser, or browse the Markdown docs in `docs/markdown/`.

Or visit the online docs: [Apple News API PHPDoc Documentation](https://www.dealmobile.co.uk/docs/html/)

---

Testing
-------

[](#testing)

```
# Run tests
composer test

# Run with coverage report
composer test:coverage
```

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

---

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](LICENSE).

---

Links
-----

[](#links)

- [Apple News Format Documentation](https://developer.apple.com/documentation/applenewsformat)
- [Apple News API Documentation](https://developer.apple.com/documentation/applenewsapi)
- [Packagist Package](https://packagist.org/packages/tomgould/apple-news-api)
- [GitHub Repository](https://github.com/tomgould/apple-news-api)

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance88

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Recently: every ~22 days

Total

12

Last Release

59d ago

Major Versions

v1.0.8 → v2.0.02025-12-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/986a8674982bb0ac1fbec54b60467457d0ebfb735c8d2e22687d5a88527389f2?d=identicon)[tomgould](/maintainers/tomgould)

---

Top Contributors

[![tomgould](https://avatars.githubusercontent.com/u/2184092?v=4)](https://github.com/tomgould "tomgould (43 commits)")[![toc-assistant](https://avatars.githubusercontent.com/u/259933816?v=4)](https://github.com/toc-assistant "toc-assistant (6 commits)")

---

Tags

psr-7apipsr-18apple newspublisherapple-newsapple-news-formatanf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tomgould-apple-news-api/health.svg)

```
[![Health](https://phpackages.com/badges/tomgould-apple-news-api/health.svg)](https://phpackages.com/packages/tomgould-apple-news-api)
```

###  Alternatives

[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[claude-php/claude-php-sdk

A universal, framework-agnostic PHP SDK for the Anthropic Claude API with PSR compliance

13920.7k2](/packages/claude-php-claude-php-sdk)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)[vultr/vultr-php

The Official Vultr API PHP Wrapper.

2243.9k1](/packages/vultr-vultr-php)[amphp/http-client-psr7

PSR-7 adapter for Amp's HTTP client.

1454.7k4](/packages/amphp-http-client-psr7)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1417.1k5](/packages/chillerlan-php-httpinterface)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
