Using this site as a reference, I was studying Twitter client creation using Twitter 4J.
I would like to get a timeline on UserStream because I am easily caught in API restrictions with this method, but I don't know how to do it at all, so please let me know.
Also, when I search for ListActivity, it doesn't come out much, so I don't know the difference between ListView and ListActivity very well, so I would appreciate it if you could tell me the difference between the two.
I wrote a sample code using UserStream on Twitter 4J.I hope it will be helpful.
Learn more about UserSream here.
http://twitter4j.org/javadoc/twitter4j/TwitterStream.html
app/build.grade
compile'org.twitter4j:twitter4j-core:4.0.4'
compile'org.twitter4j:twitter4j-async:4.0.4'
compile'org.twitter4j:twitter4j-stream:4.0.4'
MainActivity
String consumerKey="here";
String consumerSecret="Your";
String accessToken="Key";
String accessTokenSecret="Input";
// config
Configuration conf = new ConfigurationBuilder()
.setDebugEnabled(true)
.setOAuthConsumerKey(consumerKey)
.setOAuthConsumerSecret(consumerSecret)
.setOAuthAccessToken(accessToken)
.setOAuthAccessTokenSecret (accessTokenSecret)
.build();
StatusListener listener = new StatusListener() {
@ Override
public void onStatus (Status status) {
// View logs in the tweet retrieval
Log.i("UserName:"+status.getUser().getName(), "Tweet:"+status.getText());
}
@ Override
public void onDeletionNotice(StatusDeletionNotice){}
@ Override
public void onTrackLimitationNotice(int numberOfLimitedStatus){}
@ Override
public void onScrubGeo(long userId,long upToStatusId){}
@ Override
public void onStallWarning(StallWarning warning){}
@ Override
public void onException (Exceptionex){}
};
TwitterStream twitterStream=new TwitterStreamFactory(conf).getInstance();
twitterStream.addListener(listener);
twitterStream.user();
The entire sample project has been published to GitHub.
https://github.com/xsota/Twitter4jUserStreamTest
See below for ListView, ListActivity.
https://developer.android.com/guide/topics/ui/layout/listview.html?hl=ja
https://developer.android.com/reference/android/app/ListActivity.html?hl=ja
© 2024 OneMinuteCode. All rights reserved.