PHP code example of amane / blog-sdk
1. Go to this page and download the library: Download amane/blog-sdk 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/ */
amane / blog-sdk example snippets
use Amane\BlogSdk\AmaneClient;
$client = new AmaneClient(
'https://service.amane.app', // baseUrl (= /api/v1 は SDK が自動付与)
'amb_xxxxxxxxxxxxx' // API token (AMANE 管理画面で発行)
);
$response = $client->articles()->list();
foreach ($response->data as $article) {
echo $article['title'] . "\n";
}
$response = $client->articles()->get('01HF3ABC...');
$article = $response->data;
echo $article['content_html']; // HTML 本文
echo $article['content_markdown']; // Markdown 本文
$client->articles()->reportPublication(
'01HF3ABC...',
'https://customer.example.com/blog/article-slug', // published_url (必須)
date('c'), // published_at (省略可)
'https://customer.example.com/blog/article-slug', // canonical_url (省略可)
'CMS で編集した実タイトル', // actual_title (省略可)
'CMS で編集した実 meta description', // actual_meta_description (省略可)
'見出しを 1 つ追加' // deviation_notes (省略可)
);
$client->articles()->updatePublication('01HF3ABC...', [
'published_url' => 'https://customer.example.com/new-slug',
]);
$client->articles()->markUnpublished('01HF3ABC...');
$response = $client->articles()->performance('01HF3ABC...');
$perf = $response->data;
echo "verdict: {$perf['verdict']}\n";
echo "position improvement: {$perf['delta']['position_improvement']}\n";
// 一覧
$response = $client->keywords()->list();
// 追加 (= keywords は配列で複数渡せる。priority は省略時 'medium')
$client->keywords()->add(['名古屋 システム開発'], 'high');
// 削除
$client->keywords()->remove('kw_xxxxxxxx');
$response = $client->topics()->list();
foreach ($response->data as $topic) {
echo $topic['title'] . "\n";
}
$response = $client->usage()->get();
echo "今月の配信数: {$response->data['delivered_count']}\n";
echo "残数: {$response->data['remaining']}\n";
use Amane\BlogSdk\Exceptions\AuthException;
use Amane\BlogSdk\Exceptions\RateLimitException;
use Amane\BlogSdk\Exceptions\AmaneApiException;
try {
$response = $client->articles()->list();
} catch (AuthException $e) {
// 401: トークン無効・失効 → 再発行を案内
error_log('AMANE 認証失敗: ' . $e->getMessage());
} catch (RateLimitException $e) {
// 429: レート制限超過 → Retry-After 秒数尊重
sleep($e->retryAfter);
} catch (AmaneApiException $e) {
// その他の API エラー (4xx/5xx)
error_log('AMANE API エラー: ' . $e->getMessage());
}