We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm back again - sorry to be asking another question today - I'm having issues with getting the the user's profile picture to display in the drawing window.
Here's the full code:
import twitter4j.util.*;
import twitter4j.*;
import twitter4j.management.*;
import twitter4j.api.*;
import twitter4j.conf.*;
import twitter4j.json.*;
import twitter4j.auth.*;
static String OAuthConsumerKey = "...";
static String OAuthConsumerSecret = "... ";
static String AccessToken = "...";
static String AccessTokenSecret = "... ";
String keywords[] = {"meaning of life"};
PImage bg;
int y;
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
void setup(){
size(1920,1080);
noStroke();
connectTwitter();
twitterStream.addListener(listener);
size(1920, 1080);
//bg = loadImage("twitterbackground.jpg");
if (keywords.length==0){
twitterStream.sample();
}
else{
twitterStream.filter(new FilterQuery().track(keywords));
}
}
//void draw() {
//background(bg);
// }
void connectTwitter() {
twitterStream.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
AccessToken accessToken = loadAccessToken();
twitterStream.setOAuthAccessToken(accessToken);
}
// Loading up the access token
private static AccessToken loadAccessToken() {
return new AccessToken(AccessToken, AccessTokenSecret);
}
StatusListener listener = new StatusListener(){
public void onStatus(Status status){
String tweets = status.getText();
String user = "@" + status.getUser().getScreenName();
tweets = user + " - " + tweets;
println(tweets);
status.getUser().getBiggerProfileImageURL();
//ImageIcon = new ImageIcon(url);
//Jlabel1.setIcon(img);
text(status.getText(), random(width), random(height), 300, 200);
text("@" + status.getUser().getScreenName(), random(width), random(height), 300, 200);
}
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
//System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
// System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
}
public void onScrubGeo(long userId, long upToStatusId) {
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}
public void onException(Exception ex) {
ex.printStackTrace();
}
public void onStallWarning(StallWarning warning){
}
};
This line isn't coming up with any errors:
status.getUser().getBiggerProfileImageURL();
I've been looking at forums for hours trying everything I can find, and after that I have these two lines:
ImageIcon image = new ImageIcon(url);
Jlabel1.setIcon(img);
Firstly it says "cannot find anything named "url". Then for the second line it says "Cannot find anything named "jlabel1". Am I missing a library or something?
Thank you so much - I know I'm probably making a very simple obvious mistake here.
Answers
there's not enough code there for us to be able to say for certain. we'd need the definitions of url and Jlabel1 at the very least.
but it looks like a scope problem.
I've put the full code up now. Thank you for taking a look!
it's not finding those members because you aren't defining them!
perhaps url is the result from line 64 and img is the result of line 66. but currently you're ignoring the first and have commented out the second 8)
this thread might be of help. Keep in mind this is using a different version of twitter4j.
http://forum.processing.org/one/topic/twitter-streaming.html