PHPackages                             toarupg0318/hatena-blog-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. toarupg0318/hatena-blog-client

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

toarupg0318/hatena-blog-client
==============================

A Hatena blog client package.

1.0.0(2y ago)15[7 issues](https://github.com/toarupg0318/hatena-blog-client/issues)MITPHPPHP ^8.1

Since May 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/toarupg0318/hatena-blog-client)[ Packagist](https://packagist.org/packages/toarupg0318/hatena-blog-client)[ RSS](/packages/toarupg0318-hatena-blog-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

 [![](https://github.com/toarupg0318/hatena-blog-client/raw/master/art/example.png)](https://github.com/toarupg0318/hatena-blog-client/raw/master/art/example.png)

 [![](https://camo.githubusercontent.com/805e8bb62bc416d895f0c1dcec8c9c5be304eb2a692e330caf5e64d4267e295e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c206d61782d636f726e666c6f776572626c75652e7376673f7374796c653d666c6174266c6f676f3d706870)](https://camo.githubusercontent.com/805e8bb62bc416d895f0c1dcec8c9c5be304eb2a692e330caf5e64d4267e295e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c206d61782d636f726e666c6f776572626c75652e7376673f7374796c653d666c6174266c6f676f3d706870) [![](https://camo.githubusercontent.com/74ea3d774c5103e6783dc09d57ef2525e1ddb80fee772cd83c2f766cf7e62e78/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://camo.githubusercontent.com/74ea3d774c5103e6783dc09d57ef2525e1ddb80fee772cd83c2f766cf7e62e78/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667) [![](https://github.com/toarupg0318/hatena-blog-client/actions/workflows/test.yml/badge.svg)](https://github.com/toarupg0318/hatena-blog-client/actions/workflows/test.yml/badge.svg) [ ![](https://camo.githubusercontent.com/c6a4a39e196473ecceee6971cd2851ec663f1f1f94311f87909f79fbc86b5720/68747470733a2f2f636f6465636f762e696f2f67682f746f6172757067303331382f686174656e612d626c6f672d636c69656e742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d524438524141564c3036) ](https://codecov.io/gh/toarupg0318/hatena-blog-client)

使い方
---

[](#使い方)

> [PHP 8.1+](https://php.net/releases/) が必要です

### 準備

[](#準備)

はじめに、はてなブログに接続するために認証情報を[詳細設定](https://blog.hatena.ne.jp/my/config/detail)から取得してください。

設定 &gt; 詳細設定 [![](https://github.com/toarupg0318/hatena-blog-client/raw/master/art/hatena_secrets.png)](https://github.com/toarupg0318/hatena-blog-client/raw/master/art/hatena_secrets.png)

以下コマンドでcomposerでインストールしてください。

```
composer require toarupg0318/hatena-blog-client
```

以下のようにクライアントインスタンスを取得します。

```
use Toarupg0318\HatenaBlogClient\HatenaClient;
...
$hatenaClient = HatenaClient::getInstance(
    'あなたのはてなID',
    'あなたのブログID',
    'あなたのAPIキー'
);
```

### 記事投稿

[](#記事投稿)

- HTMLモード（見たままモード）
- はてな記法モード

での投稿ができます。 ※ マークダウン記法は未実装です。
以下、各モードでのサンプルコードを記載します。

#### `HTMLモード（見たままモード）`

[](#htmlモード見たままモード)

事前に[基本設定](https://blog.hatena.ne.jp/my/config)で編集モードは"見たままモード"に切り替えてください。

```
    $content = getParsedData();  // レスポンス取得
// $response->getEntryId();     // ブログのエントリID（記事のユニークID）の取得
```

投稿編集画面では以下のようになります。 [![](https://github.com/toarupg0318/hatena-blog-client/raw/master/art/html_post.png)](https://github.com/toarupg0318/hatena-blog-client/raw/master/art/html_post.png)

#### `はてな記法モード`

[](#はてな記法モード)

事前に[基本設定](https://blog.hatena.ne.jp/my/config)で編集モードは"はてな記法モード"に切り替えてください。

```
$hatenaSyntaxContent
    = HatenaDOMDocument::create()
        ->appendTableOfContents()
        ->appendH3('見出し h3')
        ->appendH4('見出し h4')
        ->appendH5('見出し h5')
        ->appendText(
            getList();

// レスポンスを連想配列形式で取得
$getListResponse->getParsedData();

// また、記事一覧取得に限らず、以下のようにレスポンスを取得することもできます
// この場合、XML形式の文字列となります
// $getListResponse
//    ->getBody()
//    ->getContents();
```

最新10件以降の古い投稿は後述する"次のページURL"を引数に指定して実行することで取得できます。

```
$hatenaClient
    ->getList('https://blog.hatena.ne.jp/foo765/foo765.hatenablog.com/atom/entry?page=1695039555');
    ->getParsedData();
```

"次のページURL"は以下のように取得できます。

```
$getListResponse = $hatenaClient->getList();
$getListResponse->getNextPageUrl();
// 'https://blog.hatena.ne.jp/foo765/foo765.hatenablog.com/atom/entry?page=1695039555'
```

### 記事取得

[](#記事取得)

```
// 最新のエントリIDを取得する
$latestEntryId
    = $hatenaClient
        ->getList()
        ->getParsedEntries()[0]['entryId'] ?? null;

$getEntryResponse = $hatenaClient->getPostByEntryId($latestEntryId);
```

### 記事編集

[](#記事編集)

```
$hatenaSyntaxContent
    = HatenaDOMDocument::create()
        ->appendTableOfContents()
        ->appendH3('見出し h3')
        ->appendH4('見出し h4');
$editResponse = $hatenaClient
    ->edit(
        entryId: '4207575167685628272',
        content: $contentToEdit,
        draft: false,
        customUrl: 'happy new year 2023'
    )
    ->getParsedData();
```

※ 既存の公開記事を下書きに変更することはできません。

### 記事削除

[](#記事削除)

取得したエントリIDを引数に指定して記事を削除することができます。

```
$hatenaClient->deletePostByEntryId('4207575167685628272');
```

開発者向け
-----

[](#開発者向け)

### 開発への参加

[](#開発への参加)

開発の方針がまだ定まっていないですが、プルリクエストは適宜受け付けています。

### テストの実行

[](#テストの実行)

プロジェクトのルートディレクトリの .env.example をコピーして .env を作成します。

```
cp .env.example .env
```

新規作成した .env に自分のはてなブログAtomPub接続情報を追記します。

```
HATENA_ID=hoge6789
HATENA_BLOG_ID=hoge6789.hatenablog.com
HATENA_API_KEY=foo78bar90
```

その後、以下コマンドで [Pest](https://pestphp.com/) によるテストを実行できます。

```
./vendor/bin/pest
```

### 静的解析

[](#静的解析)

#### PHPStan

[](#phpstan)

以下コマンドで [PHPStan](https://phpstan.org/) による静的解析を実行できます。

```
./vendor/bin/phpstan analyse
```

#### Rector

[](#rector)

以下コマンドで [Rector](https://github.com/rectorphp/rector/) による静的解析を実行できます。

```
./vendor/bin/rector process src

# dry run
# ./vendor/bin/rector process src --dry-run
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1089d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/283ff8bd69f2dce52662ed928c126c88b4f4a8e9faaea649aa62855dfcb370c9?d=identicon)[toarupg0318](/maintainers/toarupg0318)

---

Top Contributors

[![toarupg0318](https://avatars.githubusercontent.com/u/129402082?v=4)](https://github.com/toarupg0318 "toarupg0318 (14 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/toarupg0318-hatena-blog-client/health.svg)

```
[![Health](https://phpackages.com/badges/toarupg0318-hatena-blog-client/health.svg)](https://phpackages.com/packages/toarupg0318-hatena-blog-client)
```

###  Alternatives

[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
