Skip to content

Latest commit

 

History

History
150 lines (120 loc) · 30.9 KB

README.md

File metadata and controls

150 lines (120 loc) · 30.9 KB

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

  • Kotlin 1.7.10
  • Twitter4J 4.0.7

Supported APIs

End-point twitter4j-v2 method
Tweets Tweet Lookup GET /2/tweets Twitter.v2.getTweets()
Manage Tweets POST /2/tweets Twitter.v2.createTweet()
DELETE /2/tweets/:id Twitter.v2.deleteTweet()
Timelines GET /2/users/:id/tweets Twitter.v2.getUserTweets()
GET /2/users/:id/mentions Twitter.v2.getUserMentions()
GET /2/users/:id/timelines/reverse_chronological Twitter.v2.getReverseChronologicalTimeline()
Search Tweets GET /2/tweets/search/recent Twitter.v2.searchRecent()
GET /2/tweets/search/all Twitter.v2.searchAll()
Tweet counts GET /2/tweets/counts/recent Twitter.v2.countRecent()
GET /2/tweets/counts/all Twitter.v2.countAll()
Filtered stream GET /2/tweets/search/stream N/A #1
Volume stream GET /2/tweets/sample/stream N/A #1
Retweets lookup GET /2/tweets/:id/retweeted_by Twitter.v2.getRetweetUsers()
Quote Tweets lookup GET /2/tweets/:id/quote_tweets Twitter.v2.getQuoteTweets()
Manage Retweets POST /2/users/:id/retweets Twitter.v2.retweet()
DELETE /2/users/:id/retweets/:source_tweet_id Twitter.v2.unretweet()
Likes lookup GET /2/tweets/:id/liking_users Twitter.v2.getLikingUsers()
GET /2/users/:id/liked_tweets Twitter.v2.getLikedTweets()
Manage Likes POST /2/users/:id/likes Twitter.v2.likeTweet()
DELETE /2/users/:id/likes/:tweet_id Twitter.v2.unlikeTweet()
Bookmarks GET /2/users/:id/bookmarks Twitter.v2.getBookmarks()
POST /2/users/:id/bookmarks Twitter.v2.addBookmark()
DELETE /2/users/:id/bookmarks/:tweet_id Twitter.v2.deleteBookmark()
Hide replies PUT /2/tweets/:id/hidden N/A (Twitter4J v4.0.7 does not support PUT methods that contain json parameters.)
Users Users lookup GET /2/users Twitter.v2.getUsers()
GET /2/users/by Twitter.v2.getUsersBy()
GET /2/users/me Twitter.v2.getMe()
Follows lookup GET /2/users/:id/following Twitter.v2.getFollowingUsers()
GET /2/users/:id/followers Twitter.v2.getFollowerUsers()
Manage follows POST /2/users/:id/following Twitter.v2.followUser()
DELETE /2/users/:source_user_id/following/:target_user_id Twitter.v2.unfollowUser()
Blocks lookup GET /2/users/:id/blocking Twitter.v2.getBlockingUsers()
Manage blocks POST /2/users/:id/blocking Twitter.v2.blockUser()
DELETE /2/users/:source_user_id/blocking/:target_user_id Twitter.v2.unblockUser()
Mutes lookup GET /2/users/:id/muting Twitter.v2.getMutingUsers()
Manage mutes POST /2/users/:id/muting Twitter.v2.muteUser()
DELETE /2/users/:source_user_id/muting/:target_user_id Twitter.v2.unmuteUser()
Spaces Spaces lookup GET /2/spaces Twitter.v2.getSpaces()
GET /2/spaces/by/creator_ids Twitter.v2.getSpacesByCreatorIds()
Spaces search GET /2/spaces/search Twitter.v2.searchSpaces()
Lists Lists lookup GET /2/lists/:id Twitter.v2.getList()
GET /2/users/:id/owned_lists Twitter.v2.getOwnedLists()
Manage Lists POST /2/lists Twitter.v2.createList()
DELETE /2/lists/:id Twitter.v2.deleteList()
PUT /2/lists/:id N/A (Twitter4J v4.0.7 does not support PUT methods that contain json parameters.)
Lists Tweets lookup GET /2/lists/:id/tweets Twitter.v2.getListTweets()
List members GET /2/lists/:id/members Twitter.v2.getListMembers()
GET /2/users/:id/list_memberships Twitter.v2.getListMemberships()
POST /2/lists/members Twitter.v2.addListMember()
DELETE /2/lists/members/:user_id Twitter.v2.deleteListMember()
Lists follows GET /2/lists/:id/followers Twitter.v2.getListFollowers()
GET /2/users/:id/followed_lists Twitter.v2.getFollowedLists()
POST /2/users/:id/followed_lists Twitter.v2.followList()
DELETE /2/users/followed_lists/:list_id Twitter.v2.unfollowList()
Pinned Lists GET /2/users/:id/pinned_lists Twitter.v2.getPinnedLists()
POST /2/users/:id/pinned_lists Twitter.v2.pinList()
DELETE /2/users/pinned_lists/:list_id Twitter.v2.unpinList()

v2 APIs table from Twitter API endpoint map

See also Response Field Mapping

Developed By

TAKEUCHI Hiroaki (@takke) - 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.