daVinci / ghost
访问Ghost的API的PHP客户端库
2.0.0
2022-05-31 13:29 UTC
Requires
- php: >=7.0
- ext-curl: *
- ext-json: *
- firebase/php-jwt: ^5.4
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/php-code-coverage: ^3.3.0
- phpunit/phpunit: ^5.3
This package is auto-updated.
Last update: 2024-08-29 05:44:23 UTC
README
访问Ghost的API的PHP客户端库(适用于Ghost >= 5.0)
对于Ghost < 5.0,请使用项目的1.0.0版本:1.0.0
安装
此页面包含有关安装PHP库的信息。
要求
- PHP版本7.0.0或更高版本
- Curl PHP扩展
- Json PHP扩展
使用Composer
您可以通过将其添加到composer.json中的依赖项来安装库。
$ composer require davaxi/ghost
或
{ "require": { "davaxi/ghost": "^1.0" } }
用法
配置客户端身份验证
使用官方文档创建令牌:https://ghost.org/docs/content-api/
使用环境设置凭据
替换为您自己的值
GHOST_API_URL=XXXXXX GHOST_ADMIN_API_KEY=YYYYYY GHOST_CONTENT_API_KEY=ZZZZZZZ
在您的PHP中
<?php $client = new Davaxi\Ghost\Client(); $client->loadFromEnvironment();
直接设置凭据
在您的PHP中
<?php $client = new Davaxi\Ghost\Client(); $client->setApiUrl('YOUR_GHOST_API_URL'); // If you are using Admin APIs $client->setAdminApiKey('YOUR_ADMIN_API_KEY'); // If you are using Content APIs $client->setContentApiKey('YOUR_CONTENT_API_KEY');
文档
Ghost管理员API
帖子
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\AdminApi\Posts($client); $response = $service->find(['YOUR_PARAMS']); $response = $service->findById('POST_ID'); $response = $service->findBySlug('POST_SLUG'); $response = $service->create(['YOUR_POSTS_DATA']); $response = $service->createOne(['YOUR_POST_DATA']); $response = $service->update('POST_ID', ['YOUR_POST_DATA']); $response = $service->delete('POST_ID');
页面
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\AdminApi\Pages($client); $response = $service->find(['YOUR_PARAMS']); $response = $service->findById('PAGES_ID'); $response = $service->findBySlug('PAGES_SLUG'); $response = $service->create(['YOUR_PAGES_DATA']); $response = $service->createOne(['YOUR_PAGES_DATA']); $response = $service->update('PAGE_ID', ['YOUR_PAGE_DATA']); $response = $service->delete('PAGE_ID');
标签
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\AdminApi\Tags($client); $response = $service->find(['YOUR_PARAMS']); $response = $service->findById('TAGS_ID'); $response = $service->findBySlug('TAGS_SLUG'); $response = $service->create(['YOUR_TAGS_DATA']); $response = $service->createOne(['YOUR_TAGS_DATA']); $response = $service->update('TAG_ID', ['YOUR_TAG_DATA']); $response = $service->delete('TAG_ID');
Webhooks
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\AdminApi\Webhooks($client); $response = $service->find(['YOUR_PARAMS']); $response = $service->findById('WEBHOOKS_ID'); $response = $service->findBySlug('WEBHOOKS_SLUG'); $response = $service->create(['YOUR_WEBHOOKS_DATA']); $response = $service->createOne(['YOUR_WEBHOOKS_DATA']); $response = $service->update('WEBHOOK_ID', ['YOUR_WEBHOOK_DATA']); $response = $service->delete('WEBHOOK_ID');
主题
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\AdminApi\Themes($client); $response = $service->upload('path/to/your/theme/zip/file'); $response = $service->activate('YOUR_THEME_NAME');
图片
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\AdminApi\Images($client); $response = $service->upload('path/to/your/image/file');
站点
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\AdminApi\Site($client); $response = $service->get();
Ghost内容API
帖子
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\ContentApi\Posts($client); $response = $service->find(['YOUR_PARAMS']); $response = $service->findById('POST_ID'); $response = $service->findBySlug('POST_SLUG');
页面
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\ContentApi\Pages($client); $response = $service->find(['YOUR_PARAMS']); $response = $service->findById('PAGE_ID'); $response = $service->findBySlug('PAGE_SLUG');
作者
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\ContentApi\Authors($client); $response = $service->find(['YOUR_PARAMS']); $response = $service->findById('AUTHOR_ID'); $response = $service->findBySlug('AUTHOR_SLUG');
标签
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\ContentApi\Tags($client); $response = $service->find(['YOUR_PARAMS']); $response = $service->findById('TAG_ID'); $response = $service->findBySlug('TAG_SLUG');
设置
<?php $client = new Davaxi\Ghost\Client(); // ... $service = new Davaxi\Ghost\Service\ContentApi\Settings($client); $response = $service->get();