Skip to content

ctkqiang/twitter-api-java-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter API Client Library for Java.

Note: This SDK is a preview and is not ready for production

You can find examples of using the SDK under the src/ directory

Note: Only Twitter API V2 is supported, Twitter API V2 is in early access

  • Spec API version: 2.28

  • Build date: 2021-11-09T12:07:08.200+13:00[Pacific/Auckland]

Twitter API v2 available endpoints

For more information, please visit https://developer.twitter.com/

Automatically generated by the OpenAPI Generator

Requirements

Building the API client library requires:

  1. Java 1.8+
  2. Maven/Gradle

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.twitter</groupId>
  <artifactId>twitter-api-java-sdk</artifactId>
  <version>1.0.2</version>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "com.twitter:twitter-api-java-sdk:1.0.2"

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/twitter-api-java-sdk-1.0.2.jar
  • target/lib/*.jar

Getting Started

Please follow the installation instructions and execute the following Java code:

import com.twitter.clientlib.ApiClient;
import com.twitter.clientlib.ApiException;
import com.twitter.clientlib.Configuration;
import com.twitter.clientlib.auth.*;
import com.twitter.clientlib.model.*;
import com.twitter.clientlib.api.TwitterApi;
import java.util.Set;
import java.util.Arrays;
import java.util.HashSet;
import java.time.OffsetDateTime;

public class TwitterApiExample {

    public static void main(String[] args) {
        // Credentials can be set by the following options:
        // 1. Environment variables:
        //       TWITTER_BEARER_TOKEN, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_TOKEN, TWITTER_TOKEN_SECRET
        // 2. Setting TwitterCredentials for TwitterApi(TwitterCredentials credentials).

        TwitterApi apiInstance = new TwitterApi(); 
        Boolean dryRun = true; // Boolean | Dry Run can be used with both the add and delete action, with the expected result given, but without actually taking any action in the system (meaning the end state will always be as it was when the request was submitted). This is particularly useful to validate rule changes.
        AddOrDeleteRulesRequest addOrDeleteRulesRequest = new AddOrDeleteRulesRequest(); // AddOrDeleteRulesRequest | 
        try {
            AddOrDeleteRulesResponse result = apiInstance.addOrDeleteRules(dryRun, addOrDeleteRulesRequest);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling TwitterApi#addOrDeleteRules");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Documentation for API Endpoints

All URIs are relative to https://api.twitter.com

Class Method HTTP request Description
TwitterApi addOrDeleteRules POST /2/tweets/search/stream/rules Add/Delete rules
TwitterApi createBatchComplianceJob POST /2/compliance/jobs Create compliance job
TwitterApi createTweet POST /2/tweets Creation of a Tweet
TwitterApi deleteTweetById DELETE /2/tweets/{id} Tweet delete by Tweet ID
TwitterApi findSpaceById GET /2/spaces/{id} Space lookup by Space ID
TwitterApi findSpacesByCreatorIds GET /2/spaces/by/creator_ids Space lookup by their creators
TwitterApi findSpacesByIds GET /2/spaces Space lookup up Space IDs
TwitterApi findTweetById GET /2/tweets/{id} Tweet lookup by Tweet ID
TwitterApi findTweetsById GET /2/tweets Tweet lookup by Tweet IDs
TwitterApi findUserById GET /2/users/{id} User lookup by ID
TwitterApi findUserByUsername GET /2/users/by/username/{username} User lookup by username
TwitterApi findUsersById GET /2/users User lookup by IDs
TwitterApi findUsersByUsername GET /2/users/by User lookup by usernames
TwitterApi getBatchComplianceJob GET /2/compliance/jobs/{id} Get compliance job
TwitterApi getOpenApiSpec GET /2/openapi.json Returns the open api spec document.
TwitterApi getRules GET /2/tweets/search/stream/rules Rules lookup
TwitterApi hideReplyById PUT /2/tweets/{id}/hidden Hide replies
TwitterApi listAddMember POST /2/lists/{id}/members Add a List member
TwitterApi listBatchComplianceJobs GET /2/compliance/jobs List compliance jobs
TwitterApi listIdCreate POST /2/lists Create List
TwitterApi listIdDelete DELETE /2/lists/{id} Delete List
TwitterApi listIdUpdate PUT /2/lists/{id} Update List
TwitterApi listRemoveMember DELETE /2/lists/{id}/members/{user_id} Remove a List member
TwitterApi listUserFollow POST /2/users/{id}/followed_lists Follow a List
TwitterApi listUserPin POST /2/users/{id}/pinned_lists Pin a List
TwitterApi listUserUnfollow DELETE /2/users/{id}/followed_lists/{list_id} Unfollow a List
TwitterApi listUserUnpin DELETE /2/users/{id}/pinned_lists/{list_id} Unpin a List
TwitterApi sampleStream GET /2/tweets/sample/stream Sample stream
TwitterApi searchSpaces GET /2/spaces/search Search for Spaces
TwitterApi searchStream GET /2/tweets/search/stream Filtered stream
TwitterApi tweetCountsFullArchiveSearch GET /2/tweets/counts/all Full archive search counts
TwitterApi tweetCountsRecentSearch GET /2/tweets/counts/recent Recent search counts
TwitterApi tweetsFullarchiveSearch GET /2/tweets/search/all Full-archive search
TwitterApi tweetsIdLikingUsers GET /2/tweets/{id}/liking_users Returns user objects that have liked the provided Tweet ID
TwitterApi tweetsIdRetweetingUsers GET /2/tweets/{id}/retweeted_by Returns user objects that have retweeted the provided Tweet ID
TwitterApi tweetsRecentSearch GET /2/tweets/search/recent Recent search
TwitterApi usersIdBlock POST /2/users/{id}/blocking Block User by User ID
TwitterApi usersIdBlocking GET /2/users/{id}/blocking Returns user objects that are blocked by provided user ID
TwitterApi usersIdFollow POST /2/users/{id}/following Follow User
TwitterApi usersIdFollowers GET /2/users/{id}/followers Returns user objects that follow the provided user ID
TwitterApi usersIdFollowing GET /2/users/{id}/following Following by User ID
TwitterApi usersIdLike POST /2/users/{id}/likes Causes the user (in the path) to like the specified tweet
TwitterApi usersIdLikedTweets GET /2/users/{id}/liked_tweets Returns Tweet objects liked by the provided User ID
TwitterApi usersIdMentions GET /2/users/{id}/mentions User mention timeline by User ID
TwitterApi usersIdMute POST /2/users/{id}/muting Mute User by User ID
TwitterApi usersIdMuting GET /2/users/{id}/muting Returns user objects that are muted by the provided user ID
TwitterApi usersIdRetweets POST /2/users/{id}/retweets Causes the user (in the path) to retweet the specified tweet
TwitterApi usersIdTweets GET /2/users/{id}/tweets User Tweets timeline by User ID
TwitterApi usersIdUnblock DELETE /2/users/{source_user_id}/blocking/{target_user_id} Unblock User by User ID
TwitterApi usersIdUnfollow DELETE /2/users/{source_user_id}/following/{target_user_id} Unfollow User
TwitterApi usersIdUnlike DELETE /2/users/{id}/likes/{tweet_id} Causes the user (in the path) to unlike the specified tweet
TwitterApi usersIdUnmute DELETE /2/users/{source_user_id}/muting/{target_user_id} Unmute User by User ID
TwitterApi usersIdUnretweets DELETE /2/users/{id}/retweets/{source_tweet_id} Causes the user (in the path) to unretweet the specified tweet

Documentation for Models

Authentication

The Twitter API has multiple authentication methods, that support different endpoints. To see what method an endpoint needs go here.

This library has support for OAuth 1.0a and OAuth 2.0

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%