-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArticle_api_example.php
More file actions
80 lines (67 loc) · 2.94 KB
/
Article_api_example.php
File metadata and controls
80 lines (67 loc) · 2.94 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
//Article Import examples
require_once 'ArticleAPILibrary/ApiHandler.php';
ini_set( "display_errors", 1 );
echo '<pre>';
/*
* Define your API_KEY (GUID provided by your Account manager);
* Define your API_DOMAIN eg. https://api.brafton.com
*
* */
define("API_KEY", 'b9c906b3-90a9-47a5-9246-dc491e8c70eb');
//define("API_KEY", '064d00e7-8da6-416e-b80f-bd11b592ad4b');
define("API_DOMAIN", 'https://api.brafton.com/');
/*
* Estabilish an API Connection
* API_KEY = string (GUID)
* API_DOMAIN = string (Base Url)
* (optional) $type = string/boolean(false);
* */
$type = false; //false or "curl" or "fopen". If false will determine available connection options.
$connection = new ApiHandler(API_KEY, API_DOMAIN, $type );
/*
* Retrieve a list of articles from the XML feed
* {API_DOMAIN/API_KEY/news}
*
* */
$categories = $connection->getCategoryDefinitions();
//Retrieve a complete list of articles (Last 30 days or 50 articles)
$articles = $connection->getNewsHTML();
//Retrieve a specific article denoted by ID
//$articles = $connection->getNewsItem(40116259);
/*
* Loop through the list of articles
*
* */
foreach($articles as $article){
//var_dump("First article",$article);
//use this id to uniquely identify your articles.
$id = $article->getId();
//Article Attributes
$title = $article->getHeadline();
$body = $article->getText();
$publish_date = $article->getPublishDate();
$created_date = $article->getCreatedDate();
$modified_date = $article->getLastModifiedDate();
// Optional article Attributes. Items listed here are optional only and may not exist in your feed
//See NewsCategory.php for information about the Category object
$categories = $article->getCategories(); //returns array of category objects.
$keywords = $article->getKeywords(); //returns string
//See Photo.php for information about the Photo object and PhotoInstance.php for information about each instance object.
$photos = $article->getPhotos(); //returns array of photo instance objects.
$photoId = $photos[0]->getId();
$photoAltText = $photos[0]->getAlt();
$photoOrientation = $photos[0]->getOrientation();
$photoCaption = $photos[0]->getCaption();
$extract = $article->getExtract(); //return string
$byline = $article->getByLine(); //return string
$tweet = $article->getTweetText(); //return string
$htmlTitle = $article->getHtmlTitle(); //return string
$htmlMetaDescription = $article->getHtmlMetaDescription(); //return string
$htmlMetaKeywords = $article->getHtmlMetaKeywords(); //return string
$tags = $article->getTags(); //return string
$array = compact('id', 'title', 'body', 'publish_date', 'created_date', 'modified_date', 'categories', 'keywords', 'photos', 'extract', 'byline', 'tweet', 'htmlTitle', 'htmlMetaDescription', 'htmlMetaKeywords', 'tags');
//var_dump($array);
//establish connection with your platforms Database and store the article
}
?>