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
Building the API client library requires:
- Java 1.8+
- Maven/Gradle
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.
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>
Add this dependency to your project's build file:
compile "com.twitter:openapi-java-client:latest"
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
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();
}
}
}
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 |
- AddOrDeleteRulesRequest
- AddOrDeleteRulesResponse
- AddRulesRequest
- AddRulesResponse
- AnimatedGif
- AnimatedGifAllOf
- CashtagEntity
- CashtagFields
- ClientDisconnectedProblem
- ClientForbiddenProblem
- ClientForbiddenProblemAllOf
- ComplianceJob
- ComplianceJobStatus
- ComplianceJobType
- ConflictProblem
- ConnectionExceptionProblem
- ConnectionExceptionProblemAllOf
- ContextAnnotation
- ContextAnnotationDomainFields
- ContextAnnotationEntityFields
- CreateBatchComplianceJobRequest
- CreateTweetRequest
- CreateTweetRequestGeo
- CreateTweetRequestMedia
- CreateTweetRequestPoll
- CreateTweetRequestReply
- DeleteRulesRequest
- DeleteRulesRequestDelete
- DeleteRulesResponse
- DisallowedResourceProblem
- DisallowedResourceProblemAllOf
- DuplicateRuleProblem
- EntityIndicesInclusiveExclusive
- EntityIndicesInclusiveInclusive
- Error
- Expansions
- FieldUnauthorizedProblem
- FieldUnauthorizedProblemAllOf
- FilteredStreamingTweet
- FilteredStreamingTweetOneOf
- FilteredStreamingTweetOneOfMatchingRules
- FullTextEntities
- GenericMultipleUsersLookupResponse
- GenericMultipleUsersLookupResponseMeta
- GenericProblem
- GenericProblemAllOf
- GenericTweetsTimelineResponse
- GenericTweetsTimelineResponseMeta
- Geo
- GetRulesResponse
- Granularity
- HashtagEntity
- HashtagFields
- HideReplyByIdRequest
- HideReplyByIdResponse
- HideReplyByIdResponseData
- InvalidRequestProblem
- InvalidRequestProblemAllOf
- InvalidRequestProblemAllOfErrors
- InvalidRuleProblem
- ListAddMemberRequest
- ListCreateRequest
- ListCreateResponse
- ListDeleteResponse
- ListDeleteResponseData
- ListFollowRequest
- ListFollowedResponse
- ListFollowedResponseData
- ListLookupMultipleUsersLookupResponse
- ListLookupMultipleUsersLookupResponseMeta
- ListMemberResponse
- ListMemberResponseData
- ListPinRequest
- ListPinnedResponse
- ListPinnedResponseData
- ListUpdateRequest
- ListUpdateResponse
- ListUpdateResponseData
- ListsIdTweetsResponse
- Media
- MentionEntity
- MentionFields
- MultiComplianceJobResponse
- MultiListNoPaginationResponse
- MultiListNoPaginationResponseMeta
- MultiListResponse
- MultiListResponseMeta
- MultiSpaceLookupResponse
- MultiTweetLookupResponse
- MultiUserLookupResponse
- NonCompliantRulesProblem
- OperationalDisconnectProblem
- OperationalDisconnectProblemAllOf
- Photo
- PhotoAllOf
- Place
- PlaceType
- Point
- Poll
- PollOption
- Problem
- ProblemOrError
- ReplySettings
- ResourceNotFoundProblem
- ResourceNotFoundProblemAllOf
- ResourceUnauthorizedProblem
- ResourceUnauthorizedProblemAllOf
- ResourceUnavailableProblem
- ResourceUnavailableProblemAllOf
- Rule
- RuleNoId
- RulesCapProblem
- RulesRequestSummary
- RulesRequestSummaryOneOf
- RulesRequestSummaryOneOf1
- RulesResponseMetadata
- SearchCount
- SingleComplianceJobResponse
- SingleListLookupResponse
- SingleSpaceLookupResponse
- SingleTweetLookupResponse
- SingleUserLookupResponse
- Space
- SpaceTopics
- StreamingTweet
- StreamingTweetOneOf
- Tweet
- TweetAttachments
- TweetCountsResponse
- TweetCountsResponseMeta
- TweetCreateResponse
- TweetCreateResponseData
- TweetDeleteResponse
- TweetDeleteResponseData
- TweetGeo
- TweetNonPublicMetrics
- TweetOrganicMetrics
- TweetPromotedMetrics
- TweetPublicMetrics
- TweetReferencedTweets
- TweetSearchResponse
- TweetSearchResponseMeta
- TweetWithheld
- URLFields
- URLImage
- UnsupportedAuthenticationProblem
- UrlEntity
- UsageCapExceededProblem
- UsageCapExceededProblemAllOf
- User
- UserEntities
- UserEntitiesUrl
- UserPublicMetrics
- UserWithheld
- UsersBlockingMutationResponse
- UsersBlockingMutationResponseData
- UsersFollowingCreateResponse
- UsersFollowingCreateResponseData
- UsersFollowingDeleteResponse
- UsersFollowingLookupResponse
- UsersIdBlockRequest
- UsersIdFollowRequest
- UsersIdLikedTweetsResponse
- UsersIdLikedTweetsResponseMeta
- UsersIdMuteRequest
- UsersLikesCreateRequest
- UsersLikesCreateResponse
- UsersLikesCreateResponseData
- UsersLikesDeleteResponse
- UsersMutingMutationResponse
- UsersMutingMutationResponseData
- UsersRetweetsCreateRequest
- UsersRetweetsCreateResponse
- UsersRetweetsCreateResponseData
- UsersRetweetsDeleteResponse
- Video
- VideoAllOf
- VideoAllOfNonPublicMetrics
- VideoAllOfOrganicMetrics
- VideoAllOfPromotedMetrics
- VideoAllOfPublicMetrics
Authentication schemes defined for the API:
- Type: HTTP basic authentication
- Type: HTTP basic authentication
It's recommended to create an instance of ApiClient
per thread in a multithreaded environment to avoid any potential issues.