openapi-java-client

Twitter API v2

  • 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 (3.8.3+)/Gradle (7.2+)

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>org.openapitools</groupId>
  <artifactId>openapi-java-client</artifactId>
  <version>latest</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

  repositories {
    mavenCentral()     // Needed if the 'openapi-java-client' jar has been published to maven central.
    mavenLocal()       // Needed if the 'openapi-java-client' jar has been published to the local maven repo.
  }

  dependencies {
     implementation "org.openapitools: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 classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.auth.*;
import org.openapitools.client.models.*;
import org.openapitools.client.api.BookmarksApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://api.twitter.com");
    
    // Configure OAuth2 access token for authorization: OAuth2UserToken
    OAuth OAuth2UserToken = (OAuth) defaultClient.getAuthentication("OAuth2UserToken");
    OAuth2UserToken.setAccessToken("YOUR ACCESS TOKEN");

    BookmarksApi apiInstance = new BookmarksApi(defaultClient);
    String id = "id_example"; // String | The ID of the authenticated source User for whom to return results.
    Integer maxResults = 56; // Integer | The maximum number of results.
    String paginationToken = "paginationToken_example"; // String | This parameter is used to get the next 'page' of results.
    Set<String> tweetFields = Arrays.asList(); // Set<String> | A comma separated list of Tweet fields to display.
    Set<String> expansions = Arrays.asList(); // Set<String> | A comma separated list of fields to expand.
    Set<String> mediaFields = Arrays.asList(); // Set<String> | A comma separated list of Media fields to display.
    Set<String> pollFields = Arrays.asList(); // Set<String> | A comma separated list of Poll fields to display.
    Set<String> userFields = Arrays.asList(); // Set<String> | A comma separated list of User fields to display.
    Set<String> placeFields = Arrays.asList(); // Set<String> | A comma separated list of Place fields to display.
    try {
      Get2UsersIdBookmarksResponse result = apiInstance.getUsersIdBookmarks(id, maxResults, paginationToken, tweetFields, expansions, mediaFields, pollFields, userFields, placeFields);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling BookmarksApi#getUsersIdBookmarks");
      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
BookmarksApi getUsersIdBookmarks GET /2/users/{id}/bookmarks Bookmarks by User
BookmarksApi postUsersIdBookmarks POST /2/users/{id}/bookmarks Add Tweet to Bookmarks
BookmarksApi usersIdBookmarksDelete DELETE /2/users/{id}/bookmarks/{tweet_id} Remove a bookmarked Tweet
ComplianceApi createBatchComplianceJob POST /2/compliance/jobs Create compliance job
ComplianceApi getBatchComplianceJob GET /2/compliance/jobs/{id} Get Compliance Job
ComplianceApi getTweetsComplianceStream GET /2/tweets/compliance/stream Tweets Compliance stream
ComplianceApi getTweetsLabelStream GET /2/tweets/label/stream Tweets Label stream
ComplianceApi getUsersComplianceStream GET /2/users/compliance/stream Users Compliance stream
ComplianceApi listBatchComplianceJobs GET /2/compliance/jobs List Compliance Jobs
DirectMessagesApi dmConversationByIdEventIdCreate POST /2/dm_conversations/{dm_conversation_id}/messages Send a new message to a DM Conversation
DirectMessagesApi dmConversationIdCreate POST /2/dm_conversations Create a new DM Conversation
DirectMessagesApi dmConversationWithUserEventIdCreate POST /2/dm_conversations/with/{participant_id}/messages Send a new message to a user
DirectMessagesApi getDmConversationsIdDmEvents GET /2/dm_conversations/{id}/dm_events Get DM Events for a DM Conversation
DirectMessagesApi getDmConversationsWithParticipantIdDmEvents GET /2/dm_conversations/with/{participant_id}/dm_events Get DM Events for a DM Conversation
DirectMessagesApi getDmEvents GET /2/dm_events Get recent DM Events
GeneralApi getOpenApiSpec GET /2/openapi.json Returns the OpenAPI Specification document.
ListsApi getUserListMemberships GET /2/users/{id}/list_memberships Get a User's List Memberships
ListsApi listAddMember POST /2/lists/{id}/members Add a List member
ListsApi listIdCreate POST /2/lists Create List
ListsApi listIdDelete DELETE /2/lists/{id} Delete List
ListsApi listIdGet GET /2/lists/{id} List lookup by List ID.
ListsApi listIdUpdate PUT /2/lists/{id} Update List.
ListsApi listRemoveMember DELETE /2/lists/{id}/members/{user_id} Remove a List member
ListsApi listUserFollow POST /2/users/{id}/followed_lists Follow a List
ListsApi listUserOwnedLists GET /2/users/{id}/owned_lists Get a User's Owned Lists.
ListsApi listUserPin POST /2/users/{id}/pinned_lists Pin a List
ListsApi listUserPinnedLists GET /2/users/{id}/pinned_lists Get a User's Pinned Lists
ListsApi listUserUnfollow DELETE /2/users/{id}/followed_lists/{list_id} Unfollow a List
ListsApi listUserUnpin DELETE /2/users/{id}/pinned_lists/{list_id} Unpin a List
ListsApi userFollowedLists GET /2/users/{id}/followed_lists Get User's Followed Lists
SpacesApi findSpaceById GET /2/spaces/{id} Space lookup by Space ID
SpacesApi findSpacesByCreatorIds GET /2/spaces/by/creator_ids Space lookup by their creators
SpacesApi findSpacesByIds GET /2/spaces Space lookup up Space IDs
SpacesApi searchSpaces GET /2/spaces/search Search for Spaces
SpacesApi spaceBuyers GET /2/spaces/{id}/buyers Retrieve the list of Users who purchased a ticket to the given space
SpacesApi spaceTweets GET /2/spaces/{id}/tweets Retrieve Tweets from a Space.
TweetsApi addOrDeleteRules POST /2/tweets/search/stream/rules Add/Delete rules
TweetsApi createTweet POST /2/tweets Creation of a Tweet
TweetsApi deleteTweetById DELETE /2/tweets/{id} Tweet delete by Tweet ID
TweetsApi findTweetById GET /2/tweets/{id} Tweet lookup by Tweet ID
TweetsApi findTweetsById GET /2/tweets Tweet lookup by Tweet IDs
TweetsApi getRules GET /2/tweets/search/stream/rules Rules lookup
TweetsApi getTweetsFirehoseStream GET /2/tweets/firehose/stream Firehose stream
TweetsApi getTweetsIdQuoteTweets GET /2/tweets/{id}/quote_tweets Retrieve Tweets that quote a Tweet.
TweetsApi getTweetsSample10Stream GET /2/tweets/sample10/stream Sample 10% stream
TweetsApi hideReplyById PUT /2/tweets/{tweet_id}/hidden Hide replies
TweetsApi listsIdTweets GET /2/lists/{id}/tweets List Tweets timeline by List ID.
TweetsApi sampleStream GET /2/tweets/sample/stream Sample stream
TweetsApi searchStream GET /2/tweets/search/stream Filtered stream
TweetsApi spaceBuyers GET /2/spaces/{id}/buyers Retrieve the list of Users who purchased a ticket to the given space
TweetsApi spaceTweets GET /2/spaces/{id}/tweets Retrieve Tweets from a Space.
TweetsApi tweetCountsFullArchiveSearch GET /2/tweets/counts/all Full archive search counts
TweetsApi tweetCountsRecentSearch GET /2/tweets/counts/recent Recent search counts
TweetsApi tweetsFullarchiveSearch GET /2/tweets/search/all Full-archive search
TweetsApi tweetsRecentSearch GET /2/tweets/search/recent Recent search
TweetsApi usersIdLike POST /2/users/{id}/likes Causes the User (in the path) to like the specified Tweet
TweetsApi usersIdLikedTweets GET /2/users/{id}/liked_tweets Returns Tweet objects liked by the provided User ID
TweetsApi usersIdMentions GET /2/users/{id}/mentions User mention timeline by User ID
TweetsApi usersIdRetweets POST /2/users/{id}/retweets Causes the User (in the path) to retweet the specified Tweet.
TweetsApi usersIdTimeline GET /2/users/{id}/timelines/reverse_chronological User home timeline by User ID
TweetsApi usersIdTweets GET /2/users/{id}/tweets User Tweets timeline by User ID
TweetsApi usersIdUnlike DELETE /2/users/{id}/likes/{tweet_id} Causes the User (in the path) to unlike the specified Tweet
TweetsApi usersIdUnretweets DELETE /2/users/{id}/retweets/{source_tweet_id} Causes the User (in the path) to unretweet the specified Tweet
UsersApi findMyUser GET /2/users/me User lookup me
UsersApi findUserById GET /2/users/{id} User lookup by ID
UsersApi findUserByUsername GET /2/users/by/username/{username} User lookup by username
UsersApi findUsersById GET /2/users User lookup by IDs
UsersApi findUsersByUsername GET /2/users/by User lookup by usernames
UsersApi listGetFollowers GET /2/lists/{id}/followers Returns User objects that follow a List by the provided List ID
UsersApi listGetMembers GET /2/lists/{id}/members Returns User objects that are members of a List by the provided List ID.
UsersApi tweetsIdLikingUsers GET /2/tweets/{id}/liking_users Returns User objects that have liked the provided Tweet ID
UsersApi tweetsIdRetweetingUsers GET /2/tweets/{id}/retweeted_by Returns User objects that have retweeted the provided Tweet ID
UsersApi usersIdBlock POST /2/users/{id}/blocking Block User by User ID
UsersApi usersIdBlocking GET /2/users/{id}/blocking Returns User objects that are blocked by provided User ID
UsersApi usersIdFollow POST /2/users/{id}/following Follow User
UsersApi usersIdFollowers GET /2/users/{id}/followers Followers by User ID
UsersApi usersIdFollowing GET /2/users/{id}/following Following by User ID
UsersApi usersIdMute POST /2/users/{id}/muting Mute User by User ID.
UsersApi usersIdMuting GET /2/users/{id}/muting Returns User objects that are muted by the provided User ID
UsersApi usersIdUnblock DELETE /2/users/{source_user_id}/blocking/{target_user_id} Unblock User by User ID
UsersApi usersIdUnfollow DELETE /2/users/{source_user_id}/following/{target_user_id} Unfollow User
UsersApi usersIdUnmute DELETE /2/users/{source_user_id}/muting/{target_user_id} Unmute User by User ID

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

BearerToken

  • Type: HTTP basic authentication

OAuth2UserToken

  • Type: OAuth
  • Flow: accessCode
  • Authorization URL: https://api.twitter.com/2/oauth2/authorize
  • Scopes:
    • block.read: Accounts you’ve blocked.
    • block.write: Block and unblock accounts for you.
    • bookmark.read: Allows an app to read bookmarked Tweets
    • bookmark.write: Allows an app to create and delete bookmarks
    • dm.read: All your Direct Messages
    • dm.write: Send and manage Direct Messages for you
    • follows.read: People who follow you and people who you follow.
    • follows.write: Follow and unfollow people for you.
    • like.read: Tweets you’ve liked and likes you can view.
    • like.write: Like and un-like Tweets for you.
    • list.read: Lists, list members, and list followers of lists you’ve created or are a member of, including private lists.
    • list.write: Create and manage Lists for you.
    • mute.read: Accounts you’ve muted.
    • mute.write: Mute and unmute accounts for you.
    • offline.access: App can request refresh token.
    • space.read: Access all of the Spaces you can see.
    • tweet.moderate.write: Hide and unhide replies to your Tweets.
    • tweet.read: All the Tweets you can see, including Tweets from protected accounts.
    • tweet.write: Tweet and retweet for you.
    • users.read: Any account you can see, including protected accounts. Any account you can see, including protected accounts.

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