FastComments.com

FastComments Java SDK


Ово је званични Java SDK за FastComments.

Званични Java SDK за FastComments API

Репозиторијум

Погледајте на GitHub


Инсталација Internal Link

Maven

Add the Repsy repository to your project's POM:

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

Then add the dependencies you need:

<dependencies>
    <!-- API Client -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>client</artifactId>
        <version>3.0.1</version>
    </dependency>
    
    <!-- Core Library (includes SSO) -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>core</artifactId>
        <version>3.0.1</version>
    </dependency>
    
    <!-- PubSub Library (for live events) -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>pubsub</artifactId>
        <version>3.0.1</version>
    </dependency>
</dependencies>

Gradle

Add the Repsy repository to your build.gradle file:

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

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

Library Contents

This library contains three modules. The generated API client, the core Java library which contains hand-written utilities to make working with the API easier, and the pubsub module which is a library for subscribing to change feeds.

Public vs Secured APIs

For the API client, there are three classes, DefaultApi, PublicApi, and ModerationApi. The DefaultApi contains methods that require your API key, and PublicApi contains methods that can be made directly from a browser/mobile device/etc without authentication.

The ModerationApi provides an extensive suite of live and fast moderation APIs. Every ModerationApi method accepts an sso parameter and can authenticate via SSO or a FastComments.com session cookie.

Брзи почетак Internal Link

Коришћење аутентификованих API-ја (DefaultApi)

Важнo: Морате да подесите ваш API кључ на ApiClient пре слања аутентификованих захтјева. Ако то не урадите, захтјеви ће пропасти са грешком 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) {
        // Направите и конфигуришите ApiClient
        ApiClient apiClient = new ApiClient();

        // ОБАВЕЗНО: Поставите ваш API кључ (добијете га са FastComments контролне табле)
        apiClient.setApiKey("YOUR_API_KEY_HERE");

        // Направите инстанцу API-ја са конфигурисаним ApiClient-ом
        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)

Јавни endpoint-и не захтијевају аутентификацију:

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 покреће модераторску контролну таблу. Свaka метода прихвата параметар 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" error: Проверите да ли позивате apiClient.setApiKey("YOUR_KEY") прије креирања инстанце DefaultApi.
  2. Wrong API class: Користите DefaultApi за аутентификоване захтјеве на серверској страни, PublicApi за захтјеве на клијентској страни/јавне захтјеве.
  3. Null API key: SDK ће тихо прескочити аутентификацију ако је API кључ null, што ће довести до грешака 401.

Напомене Internal Link

Идентификатори емитовања

Видећете да треба да проследите broadcastId у неким API позивима. Када примите догађаје, добићете овај ID назад, па ћете знати да игноришете догађај ако планирате оптимистично применити измене на клијенту (што ћете вероватно и желети јер пружа најбоље корисничко искуство). Проследите овде UUID. ID треба да буде довољно јединствен да се не појави два пута у току једне сесије прегледача.

Потребна помоћ?

Ако наиђете на било какве проблеме или имате питања у вези са Java SDK-ом, молимо вас:

Допринеси

Допринеси су добродошли! Посетите GitHub репозиторијум за смернице о доприносу.