Twitter API Java SDK

repository·main·Indexed 43 days ago

https://github.com/xdevplatform/twitter-api-java-sdk

A Java SDK for interacting with the Twitter API v2, featuring built-in support for OAuth 2.0, automatic token refreshing, and rate-limit handling. It provides structured access to Twitter endpoints and comprehensive data models for Tweets, Users, Spaces, and Lists. Version 2.0.3 requires Java 1.8+ and Maven (3.8.3+) or Gradle (7.2+).

Tokens
123.2K
Snippets
291
Records
414
Agent score
55%

What's inside Twitter API Java SDK

  1. Explore Twitter API Model Documentation

    main

    The SDK provides comprehensive documentation for all data models used in the Twitter API. These models represent the request and response shapes for various endpoints, including Tweets, Users, Spaces, Lists, and Compliance data. You can find detailed documentation for each specific model in the docs/ directory of the repository.

    Key categories of models include:

    • Core Entities: Tweet, User, Space, List, Media.
    • Request Models: TweetCreateRequest, AddRulesRequest, BlockUserRequest.
    • Response Models: Get2TweetsResponse, Get2UsersMeResponse, ListCreateResponse.
    • Error/Problem Models: Error, Problem, ConflictProblem, ResourceNotFoundProblem.
    • Compliance Models: TweetComplianceSchema, UserComplianceSchema.
  2. Handle FieldUnauthorizedProblem errors

    main

    The FieldUnauthorizedProblem error occurs when your API credentials do not have permission to access a specific field within a resource (such as a Tweet or User). When encountering this error, you can inspect the following properties to identify exactly which field and section are causing the authorization failure:

    • field: The name of the unauthorized field (String).
    • resourceType: The type of resource being accessed (see ResourceTypeEnum).
    • section: The specific section of the response where the field resides (see SectionEnum).
  3. Understand the TweetDropComplianceSchema structure

    main

    The TweetDropComplianceSchema is a data structure used for compliance reporting. It contains a single primary property: drop, which holds a TweetComplianceSchema object. This schema is used to encapsulate compliance-related data for specific tweet drops or batches.

    | Name | Type | Description | Notes |
    |------------ | ------------- | ------------- | ------------- |
    |**drop** | [**TweetComplianceSchema**](TweetComplianceSchema.md) |  |  |
  4. Understand the UrlEntity data structure

    main
    The UrlEntity object represents a portion of text recognized as a URL within a larger text block. It provides the exact character offsets (start and end) where the URL is located, along with metadata about the URL such as its expanded form, display URL, and associated media or page titles.
  5. Handle UsageCapExceededProblem errors

    main

    The UsageCapExceededProblem is an error type indicating that a usage cap has been exceeded. When encountering this error, you can inspect its properties to determine the context of the limit hit.

    Properties

    • period (optional): Specifies the time interval for the cap (e.g., Daily or Monthly).
    • scope (optional): Specifies the level at which the cap applies (e.g., Account or Product).
  6. Handle FilteredStreamingTweetResponse from the streaming Tweet API

    main
    The FilteredStreamingTweetResponse object is the container returned by the streaming Tweet API. It can represent either a successful Tweet or an error response. When a stream is successful, the response includes the specific user-provided rules that the Tweet matched, allowing you to trace why a specific piece of data was streamed to you.
  7. Handle ResourceUnavailableProblem errors

    main

    The ResourceUnavailableProblem is an error type indicating that a specific resource (such as a Tweet, User, or Media) is not available to your authenticated session. When catching this error, you can inspect its properties to identify exactly which resource failed and why.

    Properties

    • parameter: The parameter that caused the problem.
    • resourceId: The unique identifier of the unavailable resource.
    • resourceType: The type of resource that is unavailable, represented by the ResourceTypeEnum.
  8. Understand the HTTP Problem Details error format

    main
    When the Twitter API returns an error, it follows the IETF RFC 7807 standard for HTTP Problem Details. This means error responses are structured objects that provide machine-readable and human-readable details about what went wrong. You can expect these properties in the error response body when an API call fails.