Awesome
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
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.