Apple News API PHP Client

Metadata
in package
implements JsonSerializable

FinalYes

Article metadata for Apple News Format.

Metadata provides information about the article that is not part of the document content itself, such as authors, canonical URLs, and keywords.

Tags
see
https://developer.apple.com/documentation/applenewsformat/metadata

Table of Contents

Interfaces

JsonSerializable

Properties

$authors  : array<string|int, string>
$campaignData  : array<string, array<int, string>>|null
Campaign data for advertising targeting.
$canonicalURL  : string|null
$contentGenerationType  : string|null
Content generation type indicator.
$dateCreated  : string|null
$dateModified  : string|null
$datePublished  : string|null
$excerpt  : string|null
$generatorIdentifier  : string|null
$generatorName  : string|null
$generatorVersion  : string|null
$issue  : Issue|null
Issue information for magazine/periodical content.
$keywords  : array<string|int, string>
$links  : array<string|int, array<string, string>>
$thumbnailURL  : string|null
$transparentToolbar  : bool|null
$videoURL  : string|null

Methods

addAuthor()  : self
Add an author name.
addCampaignData()  : $this
Add a campaign data entry.
addKeyword()  : self
Add a single keyword.
addKeywords()  : self
Add multiple keywords at once.
addLinkedArticle()  : self
Add a link to a related article or resource.
jsonSerialize()  : array<string, mixed>
setAsAIGenerated()  : $this
Mark the content as AI-generated.
setCampaignData()  : $this
Set campaign data for advertising targeting.
setCanonicalURL()  : self
Set the canonical URL.
setContentGenerationType()  : $this
Set the content generation type.
setDateCreated()  : self
Set the date the article was created.
setDateModified()  : self
Set the date the article was last modified.
setDatePublished()  : self
Set the date the article was published.
setExcerpt()  : self
Set the article excerpt/summary.
setGeneratorIdentifier()  : self
Set the generator identifier (e.g., 'Drupal').
setGeneratorName()  : self
Set the name of the tool that generated this document.
setGeneratorVersion()  : self
Set the version string for the generator tool.
setIssue()  : $this
Set the issue information for magazine/periodical content.
setIssueFromArray()  : $this
Set issue information from an array.
setThumbnailURL()  : self
Set the thumbnail image URL for article discovery.
setTransparentToolbar()  : self
Enable or disable transparent toolbar in the news app.
setVideoURL()  : self
Set the video URL to be used in the article tile.

Properties

$authors

private array<string|int, string> $authors = []

List of author names.

$campaignData

Campaign data for advertising targeting.

private array<string, array<int, string>>|null $campaignData = null

$canonicalURL

private string|null $canonicalURL = null

Canonical URL of the original article.

$contentGenerationType

Content generation type indicator.

private string|null $contentGenerationType = null

Set to "AI" for AI-generated content as required by Apple policy.

$dateCreated

private string|null $dateCreated = null

ISO 8601 creation date.

$dateModified

private string|null $dateModified = null

ISO 8601 modification date.

$datePublished

private string|null $datePublished = null

ISO 8601 publication date.

$excerpt

private string|null $excerpt = null

Short summary of the article.

$generatorIdentifier

private string|null $generatorIdentifier = null

CMS or tool that generated the article.

$generatorName

private string|null $generatorName = null

Name of the generator tool.

$generatorVersion

private string|null $generatorVersion = null

Version of the generator tool.

$issue

Issue information for magazine/periodical content.

private Issue|null $issue = null

$keywords

private array<string|int, string> $keywords = []

List of tags/keywords.

private array<string|int, array<string, string>> $links = []

Relationship links.

$thumbnailURL

private string|null $thumbnailURL = null

URL for the article's tile image.

$transparentToolbar

private bool|null $transparentToolbar = null

Whether the toolbar should be transparent.

$videoURL

private string|null $videoURL = null

URL for a video to play in the article tile.

Methods

addAuthor()

Add an author name.

public addAuthor(string $author) : self
Parameters
$author : string
Return values
self

addCampaignData()

Add a campaign data entry.

public addCampaignData(string $key, array<int, string> $values) : $this

Adds or merges values for a specific campaign data key.

Parameters
$key : string

The campaign data key.

$values : array<int, string>

The values to associate with this key.

Return values
$this

addKeyword()

Add a single keyword.

public addKeyword(string $keyword) : self
Parameters
$keyword : string
Return values
self

addKeywords()

Add multiple keywords at once.

public addKeywords(array<string|int, string> $keywords) : self
Parameters
$keywords : array<string|int, string>
Return values
self

addLinkedArticle()

Add a link to a related article or resource.

public addLinkedArticle(string $url, string $relationship) : self
Parameters
$url : string

Target URL.

$relationship : string

Relationship type (e.g., 'related').

Return values
self

jsonSerialize()

public jsonSerialize() : array<string, mixed>
Return values
array<string, mixed>

setAsAIGenerated()

Mark the content as AI-generated.

public setAsAIGenerated() : $this

Convenience method that sets contentGenerationType to "AI". Use this for any content that was primarily generated by AI.

Return values
$this

setCampaignData()

Set campaign data for advertising targeting.

public setCampaignData(array<string, array<int, string>> $campaignData) : $this

Campaign data allows you to provide key-value pairs that can be used for advertising targeting. Each key maps to an array of string values.

Example:

$metadata->setCampaignData([
    'sport' => ['football', 'basketball'],
    'region' => ['west-coast']
]);
Parameters
$campaignData : array<string, array<int, string>>

Key-value pairs for ad targeting.

Return values
$this

setCanonicalURL()

Set the canonical URL.

public setCanonicalURL(string $url) : self
Parameters
$url : string
Return values
self

setContentGenerationType()

Set the content generation type.

public setContentGenerationType(string $type) : $this

Use "AI" to indicate that the article content was generated by artificial intelligence. This disclosure is required by Apple policy for AI-generated content.

Parameters
$type : string

The content generation type (e.g., "AI").

Return values
$this

setDateCreated()

Set the date the article was created.

public setDateCreated(DateTimeInterface|string $date) : self
Parameters
$date : DateTimeInterface|string
Return values
self

setDateModified()

Set the date the article was last modified.

public setDateModified(DateTimeInterface|string $date) : self
Parameters
$date : DateTimeInterface|string
Return values
self

setDatePublished()

Set the date the article was published.

public setDatePublished(DateTimeInterface|string $date) : self
Parameters
$date : DateTimeInterface|string
Return values
self

setExcerpt()

Set the article excerpt/summary.

public setExcerpt(string $excerpt) : self
Parameters
$excerpt : string
Return values
self

setGeneratorIdentifier()

Set the generator identifier (e.g., 'Drupal').

public setGeneratorIdentifier(string $identifier) : self
Parameters
$identifier : string
Return values
self

setGeneratorName()

Set the name of the tool that generated this document.

public setGeneratorName(string $name) : self
Parameters
$name : string
Return values
self

setGeneratorVersion()

Set the version string for the generator tool.

public setGeneratorVersion(string $version) : self
Parameters
$version : string
Return values
self

setIssue()

Set the issue information for magazine/periodical content.

public setIssue(Issue $issue) : $this

Use this to associate the article with a specific publication issue.

Parameters
$issue : Issue

The issue object.

Return values
$this

setIssueFromArray()

Set issue information from an array.

public setIssueFromArray(array<string, mixed> $issueData) : $this

Convenience method to set issue data without creating an Issue object.

Example:

$metadata->setIssueFromArray([
    'issueIdentifier' => 'issue-2024-01',
    'issueDate' => '2024-01-15',
    'issueName' => 'January 2024'
]);
Parameters
$issueData : array<string, mixed>

The issue data.

Return values
$this

setThumbnailURL()

Set the thumbnail image URL for article discovery.

public setThumbnailURL(string $url) : self
Parameters
$url : string
Return values
self

setTransparentToolbar()

Enable or disable transparent toolbar in the news app.

public setTransparentToolbar(bool $transparent) : self
Parameters
$transparent : bool
Return values
self

setVideoURL()

Set the video URL to be used in the article tile.

public setVideoURL(string $url) : self
Parameters
$url : string
Return values
self

        
On this page

Search results