Twitter4j v3.0.3
in
Contributed Library Questions
•
6 months ago
Hi
I am trying to modify some code to work with twitter4j v3.0.3...I've dragged and dropped the relevant twitter4j.jar file into my sketch (so it appears in a code folder). I keep getting a "cannot convert twitter to twitter" error when I try to run the code below. Any ideas?
- // This is where you enter your Oauth info
static String OAuthConsumerKey = "XXX";
static String OAuthConsumerSecret = "XXX";
// This is where you enter your Access Token info
static String AccessToken = "XXXX";
static String AccessTokenSecret = "XXXX";
// Just some random variables kicking around
String myTimeline;
java.util.List statuses = null;
User[] friends;
TwitterFactory twitterFactory;
Twitter twitter;
RequestToken requestToken;
String[] theSearchTweets = new String[11];
void setup() {
size(100, 100);
background(0);
connectTwitter();
getTimeline();
getSearchTweets();
}
void draw() {
background(0);
} - // Initial connection
void connectTwitter() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(OAuthConsumerKey);
cb.setOAuthConsumerSecret( OAuthConsumerSecret );
cb.setOAuthAccessToken( AccessToken);
cb.setOAuthAccessTokenSecret( AccessTokenSecret );
twitterFactory = new TwitterFactory(cb.build());
twitter = twitterFactory.getInstance();
println("connected");
} - // Loading up the access token
private static AccessToken loadAccessToken() {
return new AccessToken(AccessToken, AccessTokenSecret);
} - // Get your tweets
void getTimeline() {
try {
statuses = twitter.getUserTimeline();
}
catch(TwitterException e) {
println("Get timeline: " + e + " Status code: " + e.getStatusCode());
}
for (int i=0; i<statuses.size(); i++) {
Status status = (Status)statuses.get(i);
println(status.getUser().getName() + ": " + status.getText());
}
} - // Search for tweets/*
void getSearchTweets() {
String queryStr = "@RobotGrrl";
try {
Query query = new Query("source:twitter4j yusukey");
//query.setRpp(10); // Get 10 of the 100 search results
QueryResult result = twitter.search(query);
for (Status status : result.getStatus()) {
println("@" + status.getUser().getScreenName() + ":" + status.getText());
}
}
catch (TwitterException e) {
println("Search tweets: " + e);
}
}
1