FastComments.com

FastComments SDK של Java

זה ה-SDK הרשמי של Java עבור FastComments.

ה-SDK הרשמי של Java עבור ממשק ה-API של FastComments

מאגר

צפה ב-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"
}

תוכן הספרייה

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.

API ציבוריים מול API מאובטחים

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


שימוש ב-APIs מאומתים (DefaultApi)

חשוב: עליך להגדיר את מפתח ה-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) {
        // צור והגדר את לקוח ה-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 {
            // Example: Add an SSO user
            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: אימות הבקשה נכשל
        }
    }
}

שימוש ב-APIs ציבוריים (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();
}

שימוש ב-APIs למודרציה (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" error: ודא שאתה קורא ל-apiClient.setApiKey("YOUR_KEY") לפני יצירת מופע ה-DefaultApi.
  2. Wrong API class: השתמש ב-DefaultApi לבקשות מאומתות בצד השרת, וב-PublicApi לבקשות בצד הלקוח/ציבוריות.
  3. Null API key: ה-SDK ידלג על האימות בשקט אם מפתח ה-API הוא null, מה שיוביל לשגיאות 401.

הערות Internal Link

מזהי שידור

תשימו לב שעליכם להעביר broadcastId בחלק מקריאות ה־API. כשאתם מקבלים אירועים, תקבלו חזרה את המזהה הזה, כך שתדעו להתעלם מהאירוע אם אתם מתכננים להחיל שינויים בצד הלקוח באופן אופטימיסטי (מה שסביר שתרצו לעשות מאחר שזה מציע את חוויית המשתמש הטובה ביותר). העבירו כאן UUID. המזהה צריך להיות ייחודי מספיק כדי שלא יופיע פעמיים באותו סשן בדפדפן.

זקוקים לעזרה?

אם נתקלתם בבעיות או שיש לכם שאלות בנוגע ל-SDK של Java, נא:

תרומות

תרומות רצויות! אנא בקרו ב-מאגר GitHub לקבלת הנחיות לתרומה.