FastComments.com

FastComments Java SDK


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

FastComments API の公式 Java SDK

リポジトリ

GitHubで表示


インストール 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 Client -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>client</artifactId>
        <version>2.0.0</version>
    </dependency>
    
    <!-- Core Library (includes SSO) -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>core</artifactId>
        <version>2.0.0</version>
    </dependency>
    
    <!-- PubSub Library (for live events) -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>pubsub</artifactId>
        <version>2.0.0</version>
    </dependency>
</dependencies>

Gradle

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

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

dependencies {
    // API Client
    implementation "com.fastcomments:client:2.0.0"
    
    // Core Library (includes SSO)
    implementation "com.fastcomments:core:2.0.0"
    
    // PubSub Library (for live events)
    implementation "com.fastcomments:pubsub:2.0.0"
}

Library Contents

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

Public vs Secured APIs

API クライアントには DefaultApiPublicApiModerationApi の3つのクラスがあります。DefaultApi は API キーを必要とするメソッドを含み、PublicApi はブラウザ/モバイル端末等から認証なしで直接実行できるメソッドを含みます。

ModerationApi はモデレーター用ダッシュボードを支えます。コメントのモデレーションに関するメソッド(list、count、search、logs、export)、モデレーション操作(remove/restore、 flag、review/spam/approval ステータスの設定、votes、スレッドの再開/クローズ)、バン関連(コメントからのバン、バンの解除、事前バン概要、バンのステータスと設定、バンされたユーザー数)、 およびバッジと信頼(バッジの付与/削除、手動バッジ、信頼係数の取得/設定、ユーザー内部プロファイル)を含みます。すべての ModerationApi メソッドは sso パラメータを受け取るため、呼び出しを SSO で認証されたモデレーターを代理して実行できます。

クイックスタート Internal Link

認証されたAPIの使用 (DefaultApi)

重要: You must set your API key on the ApiClient before making authenticated requests. If you don't, requests will fail with a 401 error.

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();

        // REQUIRED: Set your API key (get this from your FastComments dashboard)
        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("user@example.com");
            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)

The ModerationApi drives the moderator dashboard. Each method accepts an sso parameter identifying the SSO-authenticated moderator on whose behalf the request is made:

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" error: DefaultApi インスタンスを作成する前に apiClient.setApiKey("YOUR_KEY") を呼び出していることを確認してください。
  2. Wrong API class: サーバー側の認証済みリクエストには DefaultApi を、クライアント側/パブリックなリクエストには PublicApi を使用してください。
  3. Null API key: SDK は API キーが null の場合に認証を静かにスキップするため、401 エラーが発生します。

注意事項 Internal Link

ブロードキャスト ID

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


ヘルプが必要ですか?

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

貢献

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