new to all this programming, tried perl first that didn't last long, been playing with arduino for the last couple months, thats been exciting, trying to build a project to get arduino to text message a sensor reading and be able to control a relay with a text message without the sheilds, ive been able to change my status with robotgirls example but i'm having trouble adding the directmessage command to the example, i need it to message int to a follower for the sms alert to work, please help
import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.http.*;
import twitter4j.internal.util.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.http.*;
import twitter4j.internal.util.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
/*
Just a simple Processing and Twitter thingy majiggy
RobotGrrl.com
Code licensed under:
CC-BY
CC-BY
*/
// First step is to register your Twitter application at dev.twitter.com
// Once registered, you will have the info for the OAuth tokens
// You can get the Access token info by clicking on the button on the
// right on your twitter app's page
// Good luck, and have fun!
// Once registered, you will have the info for the OAuth tokens
// You can get the Access token info by clicking on the button on the
// right on your twitter app's page
// Good luck, and have fun!
// This is where you enter your Oauth info
static String OAuthConsumerKey = "";
static String OAuthConsumerSecret = "";
static String OAuthConsumerKey = "";
static String OAuthConsumerSecret = "";
// This is where you enter your Access Token info
static String AccessToken = "";
static String AccessTokenSecret = "";
static String AccessToken = "";
static String AccessTokenSecret = "";
// Just some random variables kicking around
String myTimeline;
java.util.List statuses = null;
User[] friends;
Twitter twitter = new TwitterFactory().getInstance();
RequestToken requestToken;
String[] theSearchTweets = new String[11];
String myTimeline;
java.util.List statuses = null;
User[] friends;
Twitter twitter = new TwitterFactory().getInstance();
RequestToken requestToken;
String[] theSearchTweets = new String[11];
void setup() {
size(100,100);
background(0);
connectTwitter();
sendTweet("Hey from Simple Processing woop woop #RobotGrrl");
}
void draw() {
background(0);
}
// Initial connection
void connectTwitter() {
twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
AccessToken accessToken = loadAccessToken();
twitter.setOAuthAccessToken(accessToken);
AccessToken accessToken = loadAccessToken();
twitter.setOAuthAccessToken(accessToken);
}
// Sending a tweet
void sendTweet(String t) {
void sendTweet(String t) {
try {
Status status = twitter.updateStatus(t);
println("Successfully updated the status to [" + status.getText() + "].");
} catch(TwitterException e) {
println("Send tweet: " + e + " Status code: " + e.getStatusCode());
}
Status status = twitter.updateStatus(t);
println("Successfully updated the status to [" + status.getText() + "].");
} catch(TwitterException e) {
println("Send tweet: " + e + " Status code: " + e.getStatusCode());
}
}
// 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());
}
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());
}
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(queryStr);
query.setRpp(10); // Get 10 of the 100 search results
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
Query query = new Query(queryStr);
query.setRpp(10); // Get 10 of the 100 search results
QueryResult result = twitter.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();
theSearchTweets[i] = msg.substring(queryStr.length()+1);
Tweet t = (Tweet)tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();
theSearchTweets[i] = msg.substring(queryStr.length()+1);
println(theSearchTweets[i]);
}
}
} catch (TwitterException e) {
println("Search tweets: " + e);
}
println("Search tweets: " + e);
}
}
1