FastComments.com

FastComments Java SDK

これは FastComments の公式 Java SDK です。

FastComments API の公式 Java SDK

リポジトリ

GitHubで表示

AI コーディングエージェント Internal Link

skills.sh

FastComments のコンテキスト(ウィジェット、設定、Secure SSO、REST API、SDK)をコーディングエージェントに提供します:

npx skills add fastcomments/skills

Claude Code、Codex、Cursor、Copilot、Gemini、そして他のすべてのエージェントで、skills CLI がサポートしています。

Installation Internal Link

Maven

プロジェクトのPOMにRepsyリポジトリを追加します:

<repositories>
    <repository>
        <id>repsy</id>
        <name>FastComments Maven Repository on Repsy</name>
        <url>https://repo.repsy.io/mvn/winrid/fastcomments</url>
    </repository>
</repositories>

次に、必要な依存関係を追加します:

<dependencies>
    <!-- APIクライアント -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>client</artifactId>
        <version>3.1.2</version>
    </dependency>
    
    <!-- コアライブラリ(SSOを含む) -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>core</artifactId>
        <version>3.1.2</version>
    </dependency>
    
    <!-- PubSubライブラリ(ライブイベント用) -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>pubsub</artifactId>
        <version>3.1.2</version>
    </dependency>
</dependencies>

Gradle

build.gradleファイルにRepsyリポジトリを追加します:

repositories {
    mavenCentral()
    maven {
        url "https://repo.repsy.io/mvn/winrid/fastcomments"
    }
}

dependencies {
    // APIクライアント
    implementation "com.fastcomments:client:3.1.2"
    
    // コアライブラリ(SSOを含む)
    implementation "com.fastcomments:core:3.1.2"
    
    // PubSubライブラリ(ライブイベント用)
    implementation "com.fastcomments:pubsub:3.1.2"
}

ライブラリの内容

このライブラリには3つのモジュールが含まれています。生成されたAPIクライアント、APIの操作を容易にするための手書きユーティリティを含むコアJavaライブラリ、そして変更フィードを購読するためのライブラリであるpubsubモジュールです。

公開APIとセキュアAPI

APIクライアントには、DefaultApi、PublicApi、ModerationApiの3つのクラスがあります。DefaultApiにはAPIキーが必要なメソッドが含まれており、PublicApiには認証なしでブラウザやモバイルデバイスなどから直接実行できるメソッドが含まれています。

ModerationApiは、ライブかつ高速なモデレーションAPIの充実したスイートを提供します。すべてのModerationApiメソッドはssoパラメータを受け入れ、SSOまたはFastComments.comのセッションクッキー経由で認証できます。

Quick Start Internal Link

認証付きAPIの利用 (DefaultApi)

重要: 認証が必要なリクエストを行う前に、ApiClientにAPIキーを設定する必要があります。設定しない場合、リクエストは401エラーで失敗します。

import com.fastcomments.invoker.ApiClient;
import com.fastcomments.invoker.ApiException;
import com.fastcomments.api.DefaultApi;
import com.fastcomments.model.*;

public class Example {
    public static void main(String[] args) {
        // APIクライアントを作成して設定
        ApiClient apiClient = new ApiClient();

        // 必須: APIキーを設定(FastCommentsダッシュボードから取得)
        apiClient.setApiKey("YOUR_API_KEY_HERE");

        // 設定済みのクライアントでAPIインスタンスを作成
        DefaultApi api = new DefaultApi(apiClient);

        // これで認証付きのAPI呼び出しが可能になります
        try {
            // 例: SSOユーザーを追加
            CreateAPISSOUserData userData = new CreateAPISSOUserData();
            userData.setId("user-123");
            userData.setEmail("[email protected]");
            userData.setDisplayName("John Doe");

            AddSSOUserAPIResponse response = api.addSSOUser("YOUR_TENANT_ID", userData)
                .execute();
            System.out.println("User created: " + response);

        } catch (ApiException e) {
            System.err.println("Error: " + e.getResponseBody());
            // よくあるエラー:
            // - 401: APIキーが未設定または無効
            // - 400: リクエストの検証に失敗
        }
    }
}

公開APIの利用 (PublicApi)

公開エンドポイントは認証を必要としません:

import com.fastcomments.api.PublicApi;
import com.fastcomments.invoker.ApiException;

PublicApi publicApi = new PublicApi();

try {
    var response = publicApi.getCommentsPublic("YOUR_TENANT_ID", "page-url-id")
        .execute();
    System.out.println(response);
} catch (ApiException e) {
    e.printStackTrace();
}

モデレーションAPIの利用 (ModerationApi)

ModerationApi はモデレーターダッシュボードを動かします。各メソッドは、リクエストの対象となるSSO認証済みモデレーターを識別する sso パラメーターを受け取ります:

import com.fastcomments.api.ModerationApi;
import com.fastcomments.invoker.ApiException;
import com.fastcomments.model.*;

ModerationApi moderationApi = new ModerationApi();

try {
    // モデレーション待ちのコメントを一覧表示
    ModerationAPIGetCommentsResponse response = moderationApi.getApiComments()
        .sso("YOUR_SSO_TOKEN")
        .execute();
    System.out.println(response);
} catch (ApiException e) {
    e.printStackTrace();
}

よくある問題

  1. 401 "missing-api-key" エラー: DefaultApiインスタンスを作成する前に、必ず apiClient.setApiKey("YOUR_KEY") を呼び出してください。
  2. APIクラスの誤り: サーバーサイドの認証付きリクエストには DefaultApi を、クライアントサイド/公開リクエストには PublicApi を使用してください。
  3. APIキーがnull: APIキーがnullの場合、SDKは認証を黙ってスキップするため、401エラーが発生します。

Notes Internal Link

ブロードキャスト ID

一部の API 呼び出しでは broadcastId を渡す必要があるのが分かります。イベントを受け取ると、この ID が返されるので、クライアントに楽観的に変更を適用するつもりであれば、そのイベントを無視することができます (ユーザー体験が最も良くなるため、おそらくそうするでしょう)。ここには UUID を渡してください。ID はブラウザセッション内で二度発生しない程度に十分ユニークである必要があります。

ヘルプが必要ですか?

Java SDKに関して問題が発生した場合や質問がある場合は、次の方法でご連絡ください:

貢献

貢献は歓迎します!貢献ガイドラインについてはGitHubリポジトリを参照してください。