PHP code example of srg / ghost-api
1. Go to this page and download the library: Download srg/ghost-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
srg / ghost-api example snippets
'ghost' => [
'content_key' => env('GHOST_CONTENT_KEY'),
'admin_key' => env('GHOST_ADMIN_KEY'),
'url' => env('GHOST_URL'),
'version' => env('GHOST_VERSION'),
],
$config = [
'url' => config('services.ghost.url'),
'key' => config('services.ghost.content_key'),
'version'=> config('services.ghost.version'),
];
$api = new GhostContentAPI($config);
$rs = []; //hold results
// Browsing posts returns Promise([Post...]);
// The resolved array will have a meta property
$rs[] = $api->posts->browse(['limit' => 2, 'authors->browse();
// Reading authors returns Promise(Author);
$rs[] = $api->authors->read(['id' => 'abcd1234']);
// ray will have a meta property
$rs[] = $api->pages->browse(['limit' => 2]);
$rs[] = $api->pages->browse();
// Reading pages returns Promise(Page);
$rs[] = $api->pages->read(['id' => 'abcd1234']);
$rs[] = $api->pages->read(['slug' => 'something', 'fields' => ['title']]);
// Browsing settings returns Promise(Settings...)
// The resolved object has each setting as a key value pair
$rs[] = $api->settings->browse();
//output
dump($rs);
$config = [
'url' => config('services.ghost.url'),
'key' => config('services.ghost.admin_key'),
'version'=> config('services.ghost.version'),
];
$api = new GhostAdminAPI($config);
$rs = []; //hold results
$rs[] = $api->posts->browse();
$rs[] = $api->posts->read(['id' => 'abcd1234']);
$rs[] = $api->posts->delete(['id' => 'abcd1234']);
//todo:
//$rs[] = $api->posts->add(['title' => 'My first API post']);
//todo:
//$rs[] = $api->pages->edit(['id' => 'abcd1234', 'title' => 'Renamed my post']);
//output
dump($rs);