Hello everyone,
I have been trying to understand this code that accesses the twitter API. I have looked at the posts about the twitter API but I am having this problem.
Obviously I am not a good programmer, but I am learning. Here is what I have.
What I am trying to do is have a function that searches the twitter api and stores the results in a variable.
Then call that function, and have it return it's results to another function that formats and displays the results.
in psudocode:
void setup()
// Stuff to setup
void search()
//perform search and load results into array
void display()
//read results from search() and display with println
void draw()
search()
display()
For some reason I can not pass the results from one function to another. I am trying to get my head around this style of programming. The error is Cannot find anything named user, I assume this means it can't see the results from the other function. Thanks.
- Shawn
Quote:Twitter myTwitter = new Twitter();
void setup() {
size(800,600);
background(100);
noLoop();
}
void search() {
try {
Query query = new Query("sandwich");
query.setRpp(10);
QueryResult result = myTwitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
for (int i = 0; i < tweets.size(); i++) {
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();
//println(user + " " + msg + " " + d);
}
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
}
}
void draw() {
search();
println("Tweet by " + user); // Get error here <---
}