RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.38% (6.14%*) • Home Loan Fixed: 5.44% (6.26%*) • Fixed: 5.44% (6.26%*) • Variable: 5.38% (6.14%*) • Investment IO: 5.69% (6.52%*) • Investment PI: 5.49% (5.98%*)

Quotes API

Quotes API

Some time back we wrote a minimal Quotes WordPress plugin that'd do nothing other than render a single quote into a WordPress website. While the nature of the plugin was exceedingly simple, the API itself is quite complete, and it provides quote data to our social media and marketing system. We've recently migrated the API over to its new home in preparation for our new platform and, as always, it's available to all our current and former clients for use in any manner that floats their boat.

While the source is one of a few quotes databases that we use, it's one of the more comprehensive. This article describes (in brief) how to access the data.

The Result

Data may be queried by quote ID (for a single quote), or by search term, author, or genre. Regardless of what query is made, the data array returned in each case includes identical fields. The endpoint in all cases is as follows:

https://api.beliefmedia.com/platform/sources/quotes/quotes.json

An API Key is required, and an optional pg and number parameter may be supplied for pagination purposes. If searching results the search type must be provided: search (for text searches), author (by author_slug), or by genre (genre_slug). If no search type is provided, the browse type is assumed.

Returning a Single Quote

A single quote may be returned as follows: quotes.json?apikey=xxxxx&id=gY. The result:

1
Array
2
(
3
    [code] => 200
4
    [status] => 200
5
    [message] => OK
6
    [source] => BeliefMedia
7
    [data_version] => 0.2
8
    [data] => Array
9
        (
10
            [id] => gY
11
            [quote] => Age is an issue of mind over matter. If you don't mind, it doesn't matter.
12
            [author] => Mark Twain
13
            [full_quote] => "Age is an issue of mind over matter. If you don't mind, it doesn't matter." - Mark Twain
14
            [info] => Array
15
                (
16
                    [quote_characters] => 74
17
                    [quote_words] => 15
18
                    [author_slug] => mark-twain
19
                    [author_count] => 128
20
                    [genre_name] => Age
21
                    [genre_slug] => age
22
                    [genre_count] => 998
23
                )
24
 
25
            
Image Error
 => Array
26
                (
27
                    [filename] => mark-twain/gY.jpg
28
                    [size] => 80.5K
29
                    [width] => 885
30
                    [height] => 885
31
                )
32
 
33
        )
34
 
35
)

The image referenced is a branded quote on our server (with its parent directory). The author_slug and genre_slug in the info array are provided for search purposes.

Searching by Text, Author, Genre, or Browsing

In all search cases, the results are returned in an identical manner. Example queries are as follows:

quotes.json?apikey=xxx&type=search&search=money (searching for text "money").
quotes.json?apikey=xxx&type=author&search=mark-twain (searching Mark Twain).
quotes.json?apikey=xxx&type=genre&search=age (Searching "age" genre).
quotes.json?apikey=xxx&pg=15&number=20 (Browsing with pagination).

An example response is as follows:

1
Array
2
(
3
    [code] => 200
4
    [status] => 200
5
    [message] => OK
6
    [source] => BeliefMedia
7
    [data_version] => 0.2
8
    [page] => 1
9
    [number] => 30
10
    [pages] => 2532
11
    [total] => 75966
12
    [search] => Array
13
        (
14
            [type] => browse
15
        )
16
 
17
    [results] => Array
18
        (
19
            [0] => Array
20
                (
21
                    [id] => gY
22
                    [quote] => Age is an issue of mind over matter. If you don't mind, it doesn't matter.
23
                    [author] => Mark Twain
24
                    [full_quote] => "Age is an issue of mind over matter. If you don't mind, it doesn't matter." - Mark Twain
25
                    [info] => Array
26
                        (
27
                            [quote_characters] => 74
28
                            [quote_words] => 15
29
                            [author_slug] => mark-twain
30
                            [author_count] => 128
31
                            [genre_name] => Age
32
                            [genre_slug] => age
33
                            [genre_count] => 998
34
                        )
35
 
36
                    
Image Error
 => Array
37
                        (
38
                            [filename] => mark-twain/gY.jpg
39
                            [size] => 80.5K
40
                            [width] => 885
41
                            [height] => 885
42
                        )
43
 
44
                )
45
 
46
            [1] => Array
47
                (
48
                    [id] => jR
49
                    [quote] => Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.
50
                    [author] => Henry Ford
51
                    [full_quote] => "Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young." - Henry Ford
52
                    [info] => Array
53
                        (
54
                            [quote_characters] => 156
55
                            [quote_words] => 28
56
                            [author_slug] => henry-ford
57
                            [author_count] => 62
58
                            [genre_name] => Age
59
                            [genre_slug] => age
60
                            [genre_count] => 998
61
                        )
62
 
63
                    
Image Error
 => Array
64
                        (
65
                            [filename] => henry-ford/jR.jpg
66
                            [size] => 82.2K
67
                            [width] => 885
68
                            [height] => 885
69
                        )
70
 
71
                )
72
 
73
            [.. SNIP ..]
74
 
75
            [29] => Array
76
                (
77
                    [id] => VM
78
                    [quote] => I don't feel old. I don't feel anything till noon. That's when it's time for my nap.
79
                    [author] => Bob Hope
80
                    [full_quote] => "I don't feel old. I don't feel anything till noon. That's when it's time for my nap." - Bob Hope
81
                    [info] => Array
82
                        (
83
                            [quote_characters] => 84
84
                            [quote_words] => 17
85
                            [author_slug] => bob-hope
86
                            [author_count] => 19
87
                            [genre_name] => Age
88
                            [genre_slug] => age
89
                            [genre_count] => 998
90
                        )
91
 
92
                    
Image Error
 => Array
93
                        (
94
                            [filename] => bob-hope/VM.jpg
95
                            [size] => 77.7K
96
                            [width] => 885
97
                            [height] => 885
98
                        )
99
 
100
                )
101
 
102
        )
103
 
104
)

Image API

When have a full featured API for manufacturing images in a number of formats (including animated GIFs), and the quotes returned as above might be used with the API to return branded images. All clients will receive a zip file of branded quotes very early in our relationship. For others, a collection of around 25,000, 75,000, or 100,000 images is available for a small fee.

The background images are either user-supplied or a specific collection is chosen (the sample image below comes from the "nature" gallery). The most recent iteration of our API now returns a blurred background image by default (with crisp text it generally makes the quote pop out of the page).

Quotes API

Sample image returned from the BeliefMedia Image Factory API

The Image Factory API will be discussed another time.

Sample PHP Function

The following function is an example of one that might be used to retrieve search results.

1
<?php 
2
/*
3
 Quotes API
4
 https://www.beliefmedia.com.au/quotes-api
5
*/
6
 
7
function beliefmedia_entertainment($page = '', $number = '', $type = false, $search = false, $apikey = 'xxxxx') {
8
 
9
  if ($page == '') $page = '1';
10
  if ($number == '') $number = '20';
11
  if ($type === false) $type = 'browse';
12
 
13
  /* Correct for invalid search type */
14
  $permitted_types = array('browse', 'search', 'author', 'genre');
15
  if (!in_array($type, $permitted_types)) $type = 'browse';
16
 
17
  $type = ($type == 'browse') ? 'browse' : 'type=' . $type . '&search=' . str_replace(' ', '+', $search);
18
 
19
  $data = @file_get_contents('http://api.beliefmedia.com/platform/sources/quotes/quotes.json?apikey=' . $apikey . '&pg=' . $page . '&number=' . $number . '&' . $type);
20
  if ($data === false) return false;
21
 
22
  $data = json_decode($data, true);
23
  if ($data === false) return false;
24
 
25
  /* Likely return array of errors with code & message */
26
  if ($data['code'] != '200') return $data['message'];
27
 
28
 return (array) $data;
29
}

Usage (close the pre tags):

1
$result = beliefmedia_entertainment($page = '', $number = '', $type = false, $search = false, $apikey = 'xxxxx');
2
echo '
3
<pre>' . print_r($result, true) . '</pre>
4
 
5
';
6
 
7
$result = beliefmedia_entertainment($page = '', $number = '', $type = 'author', $search = 'mark-twain', $apikey = 'xxxxx');
8
echo '
9
<pre>' . print_r($result, true) . '</pre>
10
 
11
';
12
 
13
$result = beliefmedia_entertainment($page = '2', $number = '', $type = 'genre', $search = 'age', $apikey = 'xxxxx');
14
echo '
15
<pre>' . print_r($result, true) . '</pre>
16
 
17
';

A single result requires just the quote itemid and apikey.

Considerations

  • Searching by character count, word count etc. are all available, but their use is beyond the scope of this article.
  • Every now and again we'll make a small collection of branded images available at no cost to our Facebook or mailing list following.
  • A WordPress plugin is available to return paginated quote results in a WP website. We have another PHP script that is essentially a 'turnkey' quotes website. Both products work best with locally hosted images.
  • Most of what's quoted on the Internet is what we wanted people to say, not what they actually said. Einstein and Marilyn Monroe are probably two of the hardest hit by distorted or fake attribution. However, short quotes are often a paraphrased sentiment, giving them a certain truth.

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment