-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathPostArticle.php
More file actions
52 lines (45 loc) · 1.46 KB
/
PostArticle.php
File metadata and controls
52 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @file
* Example: POST Article
*/
require '../../src/PublisherAPI.php';
use \ChapterThree\AppleNewsAPI;
$api_key_id = "";
$api_key_secret = "";
$endpoint = "https://endpoint_url";
$PublisherAPI = new PublisherAPI(
$api_key_id,
$api_key_secret,
$endpoint
);
// An optional metadata part may also be included, to provide additional
// non-Native data about the article. The metadata part also specifies any
// sections for the article, by URL. If this part is omitted,
// the article will be published to the channel's default section.
$metadata = [
'data' => [
'isSponsored' => true,
'links' => [
'sections' => [
'https://endpoint_url/sections/{your_section_id}',
],
],
],
];
// Publishes a new article to a channel.
$response = $PublisherAPI->Post('/channels/{channel_id}/articles',
[
'channel_id' => '[CHANNEL_ID]'
],
[
// required. Apple News Native formatted JSON string.
'json' => '{"version":"0.10.13","identifier":"10","title":"Test article","language":"en","layout":{"columns":7,"width":1024},"components":[{"text":"Test article content\n\n","format":"markdown","role":"body"},{"URL":"bundle:\/\/article.jpg","role":"photo"}],"componentTextStyles":{"default":{}}}',
// List of files to POST
'files' => [
'bundle://article.jpg' => __DIR__ . '/files/article.jpg',
], // optional
// JSON metadata string
'metadata' => json_encode($metadata, JSON_UNESCAPED_SLASHES), // optional
]
);