twitter followers + servo
in
Contributed Library Questions
•
2 years ago
Hi All,
I'm new to processing and have had some success so far stumbling around but I'm at a point now where I am unsure how to proceed.
I'm trying to count the difference in followers on a twitter profile, ideally to query the number regularly and each time there is a new follower I want to move a servo 1 step with firmata and an arduino uno.
I can access the data from twitters API and display a bundle of follower user ID's (8 digit numbers) in the console box using the println command however I can't work out how to count the total number and display it as an int or something useful that I can create motor outputs from.
This is my attempt: if anyone has worked on similar problems or has suggestions for things to try I would very much appreciate comments and feedback.
import twitter4j library
String consumer_key = "xxxx";
String consumer_secret = "xxxx";
String oauth_token = "xxxx";
String oauth_token_secret = "xxxx";
AccessToken token;
String getFollowersIDs;
color bgcolor = color(255);
long timer;
PFont f; //declaring Pfont variable - not sure if this is in right place
void setup() {
size(300,300);
f = loadFont ("ArialBlack20.vlw"); // loading font
//size(640,480);
}
void draw() {
background(#ff3300);
if (millis()-timer > 2000) bgcolor = color(255);
textFont (f,20); // specifying font to be used
fill (#CCCCCC); // specifying font colour
text ("counting followers", 10,100); //display text
}
void mousePressed() {
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumer_key, consumer_secret);
token = new AccessToken(oauth_token, oauth_token_secret);
twitter.setOAuthAccessToken(token);
try {
List<Status> statuses = twitter.getUserTimeline();
System.out.println(" - " + twitter.getFollowersIDs("datatesting",-1));
for (Status status : statuses) { System.out.println(status.getUser().getName() + " - " + status.getText());
}
String[] arr = getFollowersIDs.split("datatesting",-1);
int count = 0;
for(int i = 0; i <arr.length;i++) {
if(arr[i].equals(" ")) {
}
else {
count++;
}
}
int length = count;
println(count);
} catch (TwitterException ex) {
ex.printStackTrace();
}
}
1