Skip to content

zacmos/test-client

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

  • API version: latest

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

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.twitter</groupId>
  <artifactId>openapi-java-client</artifactId>
  <version>latest</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "com.twitter:openapi-java-client:latest"

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/openapi-java-client-latest.jar
  • target/lib/*.jar

Getting Started

Please follow the installation instruction 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 are used from:
        // 1. Environment variables:
        //       TWITTER_BEARER_TOKEN, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_TOKEN, TWITTER_TOKEN_SECRET
        // 2. Can sent to TwitterApi constructor as TwitterCredentials.

        TwitterApi apiInstance = new TwitterApi(); 
        AddOrDeleteRulesRequest addOrDeleteRulesRequest = new AddOrDeleteRulesRequest(); // AddOrDeleteRulesRequest | 
        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.
        try {
            AddOrDeleteRulesResponse result = apiInstance.addOrDeleteRules(addOrDeleteRulesRequest, dryRun);
            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 findMyUser GET /2/users/me User lookup me
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 getUserListMemberships GET /2/users/{id}/list_memberships Get a User's List Memberships
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 listGetFollowers GET /2/lists/{id}/followers Returns user objects that follow a List by the provided List ID
TwitterApi listGetMembers GET /2/lists/{id}/members Returns user objects that are members of a List by the provided List ID
TwitterApi listIdCreate POST /2/lists Create List
TwitterApi listIdDelete DELETE /2/lists/{id} Delete List
TwitterApi listIdGet GET /2/lists/{id} List lookup by List ID
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 listUserOwnedLists GET /2/users/{id}/owned_lists Get a User's Owned Lists
TwitterApi listUserPin POST /2/users/{id}/pinned_lists Pin a List
TwitterApi listUserPinnedLists GET /2/users/{id}/pinned_lists Get a User's Pinned Lists
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 listsIdTweets GET /2/lists/{id}/tweets List Tweets timeline by List ID
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 spaceBuyers GET /2/spaces/{id}/buyers Retrieve the list of users who purchased a ticket to the given space
TwitterApi spaceTweets GET /2/spaces/{id}/tweets Retrieve tweets from a Space
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 userFollowedLists GET /2/users/{id}/followed_lists Get User's Followed Lists
TwitterApi usernameFollowers GET /2/users/by/username/{username}/followers Returns user objects that follow the provided username
TwitterApi usernameFollowing GET /2/users/by/username/{username}/following Following by username
TwitterApi usersByUsernameMentions GET /2/users/by/username/{username}/mentions User mention timeline by username
TwitterApi usersByUsernameTweets GET /2/users/by/username/{username}/tweets User Tweets timeline by username
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

Documentation for Authorization

Authentication schemes defined for the API:

BearerToken

  • Type: HTTP basic authentication

UserToken

  • Type: HTTP basic authentication

Recommendation

It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.

Author

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages