or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-auth.mddirect-messages.mdfavorites.mdindex.mdlists.mdplaces.mdsearch.mdstreaming.mdtimelines.mdtweets.mdusers.md
tile.json

tessl/maven-org-twitter4j--twitter4j-core

A 100% pure Java library for the Twitter API with no extra dependency

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.twitter4j/twitter4j-core@4.1.x

To install, run

npx @tessl/cli install tessl/maven-org-twitter4j--twitter4j-core@4.1.0

index.mddocs/

Twitter4J Core

Twitter4J Core is a 100% pure Java library that provides comprehensive access to the Twitter API v1.1 with no external dependencies. It offers a clean, object-oriented interface for all Twitter functionality including tweeting, timeline access, user management, search, streaming, and more.

Package Information

  • Package Name: twitter4j-core
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
        <groupId>org.twitter4j</groupId>
        <artifactId>twitter4j-core</artifactId>
        <version>4.1.2</version>
    </dependency>
  • Gradle: implementation 'org.twitter4j:twitter4j-core:4.1.2'
  • Java Version: Java 8+

Core Imports

import org.twitter4j.*;
import org.twitter4j.v1.*;

Basic Usage

import org.twitter4j.*;

public class TwitterExample {
    public static void main(String[] args) throws TwitterException {
        // Configuration via properties file (twitter4j.properties)
        Twitter twitter = Twitter.getInstance();
        
        // Or programmatic configuration
        Twitter twitter = Twitter.newBuilder()
            .oAuthConsumer("consumer key", "consumer secret")
            .oAuthAccessToken("access token", "access token secret")
            .build();
        
        // Access Twitter API v1.1
        TwitterV1 v1 = twitter.v1();
        
        // Post a tweet
        Status status = v1.tweets().updateStatus("Hello Twitter API!");
        System.out.println("Posted: " + status.getText());
        
        // Get home timeline
        ResponseList<Status> timeline = v1.timelines().getHomeTimeline();
        for (Status tweet : timeline) {
            System.out.println(tweet.getUser().getName() + ": " + tweet.getText());
        }
    }
}

Architecture

Twitter4J Core is built around several key architectural patterns:

  • Factory Pattern: Main entry through Twitter.getInstance() and Twitter.newBuilder()
  • Interface-Implementation Separation: Public APIs defined as interfaces, implementations are package-private
  • Resource Organization: Twitter API v1.1 functionality grouped into logical resource interfaces
  • Builder Pattern: Configuration and request building with type-safe builders
  • Authentication Framework: Pluggable authentication with OAuth 1.0a and OAuth 2.0 support
  • Rate Limit Awareness: Built-in rate limiting information and monitoring
  • Streaming Support: Real-time data processing with listener patterns

Capabilities

Core Configuration and Authentication

Primary entry points and authentication management for Twitter API access.

interface Twitter {
    static Twitter getInstance();
    static TwitterBuilder newBuilder();
    TwitterV1 v1();
}

class TwitterBuilder {
    TwitterBuilder oAuthConsumer(String consumerKey, String consumerSecret);
    TwitterBuilder oAuthAccessToken(String accessToken, String accessTokenSecret);
    TwitterBuilder oAuth2AccessToken(String oauth2AccessToken);
    Twitter build();
}

Core Configuration and Authentication

Tweet Operations

Complete tweet lifecycle management including posting, retrieving, deleting, and retweeting.

interface TweetsResources {
    Status updateStatus(String status) throws TwitterException;
    Status updateStatus(StatusUpdate statusUpdate) throws TwitterException;
    Status destroyStatus(long statusId) throws TwitterException;
    Status retweetStatus(long statusId) throws TwitterException;
    Status showStatus(long id) throws TwitterException;
}

Tweet Operations

Timeline Access

Access to various Twitter timelines including home timeline, user timeline, and mentions.

interface TimelinesResources {
    ResponseList<Status> getHomeTimeline() throws TwitterException;
    ResponseList<Status> getHomeTimeline(Paging paging) throws TwitterException;
    ResponseList<Status> getUserTimeline() throws TwitterException;
    ResponseList<Status> getUserTimeline(String screenName, Paging paging) throws TwitterException;
    ResponseList<Status> getMentionsTimeline() throws TwitterException;
}

Timeline Access

User Management

User profile access, lookup, search, and relationship management.

interface UsersResources {
    User showUser(String screenName) throws TwitterException;
    User showUser(long userId) throws TwitterException;
    ResponseList<User> searchUsers(String query, int page) throws TwitterException;
    ResponseList<User> lookupUsers(String[] screenNames) throws TwitterException;
    ResponseList<User> lookupUsers(long[] ids) throws TwitterException;
}

interface FriendsFollowersResources {
    User createFriendship(String screenName) throws TwitterException;
    User destroyFriendship(String screenName) throws TwitterException;
    IDs getFriendsIDs(String screenName, long cursor) throws TwitterException;
    IDs getFollowersIDs(String screenName, long cursor) throws TwitterException;
}

User Management

Search Functionality

Comprehensive search capabilities for tweets, users, and trending topics.

interface SearchResource {
    QueryResult search(Query query) throws TwitterException;
}

interface TrendsResources {
    Trends getPlaceTrends(int woeid) throws TwitterException;
    ResponseList<Location> getAvailableTrends() throws TwitterException;
    ResponseList<Location> getClosestTrends(GeoLocation location) throws TwitterException;
}

Search Functionality

Direct Messages

Private messaging functionality for sending and receiving direct messages.

interface DirectMessagesResources {
    DirectMessage sendDirectMessage(String screenName, String text) throws TwitterException;
    DirectMessage sendDirectMessage(long userId, String text) throws TwitterException;
    ResponseList<DirectMessage> getDirectMessages() throws TwitterException;
    ResponseList<DirectMessage> getSentDirectMessages() throws TwitterException;
    DirectMessage destroyDirectMessage(long id) throws TwitterException;
}

Direct Messages

Lists Management

Twitter list creation, management, and member operations.

interface ListsResources {
    UserList createUserList(String listName, boolean isPublicList, String description) throws TwitterException;
    UserList updateUserList(long listId, String newListName, boolean isPublicList, String newDescription) throws TwitterException;
    ResponseList<UserList> getUserLists(String screenName) throws TwitterException;
    ResponseList<Status> getUserListStatuses(long listId, Paging paging) throws TwitterException;
    UserList addUserListMember(long listId, long userId) throws TwitterException;
    UserList deleteUserListMember(long listId, long userId) throws TwitterException;
}

Lists Management

Favorites and Likes

Managing tweet favorites (likes) and retrieving favorite lists.

interface FavoritesResources {
    Status createFavorite(long id) throws TwitterException;
    Status destroyFavorite(long id) throws TwitterException;
    ResponseList<Status> getFavorites() throws TwitterException;
    ResponseList<Status> getFavorites(String screenName) throws TwitterException;
    ResponseList<Status> getFavorites(String screenName, Paging paging) throws TwitterException;
}

Favorites and Likes

Real-time Streaming

Real-time Twitter data streaming with customizable filters and listeners.

interface TwitterStream {
    void addListener(StreamListener listener);
    void filter(FilterQuery query);
    void sample();
    void firehose();
    void user();
    void cleanUp();
    void shutdown();
}

interface StatusListener extends StreamListener {
    void onStatus(Status status);
    void onDeletionNotice(StatusDeletionNotice statusDeletionNotice);
    void onTrackLimitationNotice(int numberOfLimitedStatuses);
    void onScrubGeo(long userId, long upToStatusId);
    void onStallWarning(StallWarning warning);
}

Real-time Streaming

Geographic and Places

Location-based functionality including places, geocoding, and geographic search.

interface PlacesGeoResources {
    ResponseList<Place> searchPlaces(GeoQuery query) throws TwitterException;
    ResponseList<Place> getSimilarPlaces(GeoLocation location, String name, String containedWithin, String streetAddress) throws TwitterException;
    ResponseList<Place> reverseGeoCode(GeoQuery query) throws TwitterException;
    Place getGeoDetails(String placeId) throws TwitterException;
}

Geographic and Places

Core Types

class TwitterException extends Exception {
    int getErrorCode();
    String getErrorMessage();
    int getStatusCode();
    boolean isCausedByNetworkIssue();
    boolean isErrorMessageAvailable();
    boolean exceededRateLimitation();
    RateLimitStatus getRateLimitStatus();
}

interface TwitterResponse {
    RateLimitStatus getRateLimitStatus();
    int getAccessLevel();
}

interface RateLimitStatus {
    int getLimit();
    int getRemaining();
    int getResetTimeInSeconds();
    int getSecondsUntilReset();
}

class AccessToken {
    AccessToken(String token, String tokenSecret);
    String getToken();
    String getTokenSecret();
    long getUserId();
    String getScreenName();
}

class OAuth2Token {
    OAuth2Token(String tokenType, String accessToken);
    String getTokenType();
    String getAccessToken();
}