Home

Awesome

v2 CI

twitter4j-v2

twitter4j-v2 is a simple wrapper for Twitter API v2 that is designed to be used with Twitter4J.

More information is here.

How do I use it?

Setup

Dependencies
repositories {
    mavenCentral()
}

dependencies {
    implementation "io.github.takke:jp.takke.twitter4j-v2:$twitter4jV2Version"
}

see search.maven.org

Example

val twitter: Twitter = yourTwitterInstanceProvider.get()
val tweetId = 656974073491156992L

val tweetsResponse = twitter.v2.getTweets(tweetId,
                            mediaFields = null,
                            placeFields = null,
                            pollFields = "duration_minutes,end_datetime,id,options,voting_status",
                            tweetFields = "id,public_metrics",
                            userFields = null,
                            expansions = "attachments.poll_ids")

println(tweetsResponse.tweets[0].poll(tweetsResponse.pollsMap))
// or
println(tweetsResponse.pollsMap[tweetsResponse.tweets[0].pollId])

// => Poll(id=656974073113636864, options=[PollOption(position=1, label=Roboto, votes=391), 
//    PollOption(position=2, label=San Francisco, votes=691)], 
//    votingStatus=CLOSED, endDatetime=Fri Oct 23 08:23:19 GMT+09:00 2015, durationMinutes=1440)

See more examples in kotlin and java.

Requirements

Supported APIs

End-pointtwitter4j-v2 method
TweetsTweet LookupGET /2/tweetsTwitter.v2.getTweets()
Manage TweetsPOST /2/tweetsTwitter.v2.createTweet()
DELETE /2/tweets/:idTwitter.v2.deleteTweet()
TimelinesGET /2/users/:id/tweetsTwitter.v2.getUserTweets()
GET /2/users/:id/mentionsTwitter.v2.getUserMentions()
GET /2/users/:id/timelines/reverse_chronologicalTwitter.v2.getReverseChronologicalTimeline()
Search TweetsGET /2/tweets/search/recentTwitter.v2.searchRecent()
GET /2/tweets/search/allTwitter.v2.searchAll()
Tweet countsGET /2/tweets/counts/recentTwitter.v2.countRecent()
GET /2/tweets/counts/allTwitter.v2.countAll()
Filtered streamGET /2/tweets/search/streamN/A #1
Volume streamGET /2/tweets/sample/streamN/A #1
Retweets lookupGET /2/tweets/:id/retweeted_byTwitter.v2.getRetweetUsers()
Quote Tweets lookupGET /2/tweets/:id/quote_tweetsTwitter.v2.getQuoteTweets()
Manage RetweetsPOST /2/users/:id/retweetsTwitter.v2.retweet()
DELETE /2/users/:id/retweets/:source_tweet_idTwitter.v2.unretweet()
Likes lookupGET /2/tweets/:id/liking_usersTwitter.v2.getLikingUsers()
GET /2/users/:id/liked_tweetsTwitter.v2.getLikedTweets()
Manage LikesPOST /2/users/:id/likesTwitter.v2.likeTweet()
DELETE /2/users/:id/likes/:tweet_idTwitter.v2.unlikeTweet()
BookmarksGET /2/users/:id/bookmarksTwitter.v2.getBookmarks()
POST /2/users/:id/bookmarksTwitter.v2.addBookmark()
DELETE /2/users/:id/bookmarks/:tweet_idTwitter.v2.deleteBookmark()
Hide repliesPUT /2/tweets/:id/hiddenN/A (Twitter4J v4.0.7 does not support PUT methods that contain json parameters.)
UsersUsers lookupGET /2/usersTwitter.v2.getUsers()
GET /2/users/byTwitter.v2.getUsersBy()
GET /2/users/meTwitter.v2.getMe()
Follows lookupGET /2/users/:id/followingTwitter.v2.getFollowingUsers()
GET /2/users/:id/followersTwitter.v2.getFollowerUsers()
Manage followsPOST /2/users/:id/followingTwitter.v2.followUser()
DELETE /2/users/:source_user_id/following/:target_user_idTwitter.v2.unfollowUser()
Blocks lookupGET /2/users/:id/blockingTwitter.v2.getBlockingUsers()
Manage blocksPOST /2/users/:id/blockingTwitter.v2.blockUser()
DELETE /2/users/:source_user_id/blocking/:target_user_idTwitter.v2.unblockUser()
Mutes lookupGET /2/users/:id/mutingTwitter.v2.getMutingUsers()
Manage mutesPOST /2/users/:id/mutingTwitter.v2.muteUser()
DELETE /2/users/:source_user_id/muting/:target_user_idTwitter.v2.unmuteUser()
SpacesSpaces lookupGET /2/spacesTwitter.v2.getSpaces()
GET /2/spaces/by/creator_idsTwitter.v2.getSpacesByCreatorIds()
Spaces searchGET /2/spaces/searchTwitter.v2.searchSpaces()
ListsLists lookupGET /2/lists/:idTwitter.v2.getList()
GET /2/users/:id/owned_listsTwitter.v2.getOwnedLists()
Manage ListsPOST /2/listsTwitter.v2.createList()
DELETE /2/lists/:idTwitter.v2.deleteList()
PUT /2/lists/:idN/A (Twitter4J v4.0.7 does not support PUT methods that contain json parameters.)
Lists Tweets lookupGET /2/lists/:id/tweetsTwitter.v2.getListTweets()
List membersGET /2/lists/:id/membersTwitter.v2.getListMembers()
GET /2/users/:id/list_membershipsTwitter.v2.getListMemberships()
POST /2/lists/membersTwitter.v2.addListMember()
DELETE /2/lists/members/:user_idTwitter.v2.deleteListMember()
Lists followsGET /2/lists/:id/followersTwitter.v2.getListFollowers()
GET /2/users/:id/followed_listsTwitter.v2.getFollowedLists()
POST /2/users/:id/followed_listsTwitter.v2.followList()
DELETE /2/users/followed_lists/:list_idTwitter.v2.unfollowList()
Pinned ListsGET /2/users/:id/pinned_listsTwitter.v2.getPinnedLists()
POST /2/users/:id/pinned_listsTwitter.v2.pinList()
DELETE /2/users/pinned_lists/:list_idTwitter.v2.unpinList()

v2 APIs table from Twitter API endpoint map

See also Response Field Mapping

Developed By

TAKEUCHI Hiroaki (<a href="https://twitter.com/takke">@takke</a>) - takke30 at gmail.com

License

Copyright 2020 takke

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.