Problems to get image from pic.twitter.com using twitter4j
in
Contributed Library Questions
•
1 year ago
Hi guys, first of all, sorry my english.
I've been only watching this forum until now, and today i'm here to ask your help to solve this problem.
I need to get pics from twitter that contain a certain #hashtag, but i'm having trouble with where pic.twitter.com store the image, it gives me a link to a site, but this site doesn't have the link to image in the source... Somebody could helpme?
here is the code:
String queryStr = "#EmicidaSonar";
PFont ca;
PFont lg;
int count=30;
float andar=0;
String textonow ="loading...";
PImage imgpx ;
String imgtx;
String msg[];
String data[];
String site;
SimpleThread thread1;
static String OAuthConsumerKey = "q3BNKd5Ko5qmBLB98HZPHw";
static String OAuthConsumerSecret = "Dsnpe1X8JAIPtYdXgFWe6IaJBpgKDW7Y1LZhVk4WcX8";
static String AccessToken = "385133110-I1xCq1KvSsn4Zx2o3uLW0OG9FihzH8ij8P73VmIQ";
static String AccessTokenSecret = "MTvp1p8oItTlZcj9g0coMn6mXdVxiIap7R3pzb8BXyE";
java.util.List statuses = null;
Twitter twitter = new TwitterFactory().getInstance();
RequestToken requestToken;
String[] theSearchTweets = new String[11];
void setup(){
imageMode(CENTER);
size(720,405);
//frameRate(24);
smooth();
thread1=new SimpleThread(5000,"tw");
thread1.start();
imgpx = requestImage("KR.jpg");
ca = loadFont("CA.vlw");
lg =loadFont("LG.vlw");
msg = new String[10];
connectTwitter();
}
void draw(){
background(20);
textFont(lg, 10);
textAlign(RIGHT);
text(int(frameRate)+" fps",width-10,height-10);
textFont(ca, 20);
textAlign(CENTER);
text(textonow, width/2,height-30);
translate(width/2, height/2);
if(imgpx!=null){
image(imgpx,0,0,imgpx.width*.2,imgpx.height*.2);
}
if(msg[0]!=null){
//println(msg[0]);
msg=match(msg[0], "http://*.............");
//println(msg[0]);
site=msg[0];
}
}
class SimpleThread extends Thread{
boolean running;
int waittime;
String id;
int count;
SimpleThread (int w, String s){
waittime = w;
running = false;
id = s;
count = 0;
}
void start () {
running = true;
println("Thread run");
super.start();
}
void run(){
while(running) {
println(id+": "+count);
count++;
getSearchTweets();
imgpx = requestImage("n.jpg");
if(site!=null){
sitedl(site);
println(data);
}
try{
sleep((long)(waittime));
} catch (Exception e) {
}
}
System.out.println(id+"thread is done");
}
void quit() {
System.out.println("QUIT");
running=false;
interrupt();
}
}
void sitedl(String tpsite) {
data = loadStrings(tpsite);
// saveBytes("n.jpg",data);
}
void connectTwitter() {
twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
AccessToken accessToken = loadAccessToken();
twitter.setOAuthAccessToken(accessToken);
}
private static AccessToken loadAccessToken(){
return new AccessToken(AccessToken, AccessTokenSecret);
}
void getSearchTweets() {
try {
Query query = new Query(queryStr);
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
Tweet t = (Tweet)tweets.get(0);
msg[0] = t.getText();
imgtx = t.getProfileImageUrl();
textonow= t.getText();
//println(msg);
}
catch (TwitterException e)
{
println("Search tweets: " + e);
}
}
1