using Rest; public class SimpleTweet { private static const string CONSUMER_KEY = "#######################"; // this comes from your app's twitter account page private static const string CONSUMER_SECRET = "########################################"; // this comes from your app's twitter account page private static const string URL_FORMAT = "https://api.twitter.com"; private static const string REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token"; private static const string FUNCTION_ACCESS_TOKEN = "oauth/access_token"; private static const string FUNCTION_STATUSES_UPDATE = "1/statuses/update.xml"; private static const string PARAM_STATUS = "status"; public static int main(string[] args) { // make sure there is a message to tweet if(args[1] == null || args[1] == "") { stdout.printf("No tweet message specified.\n"); return 0; } /** Authenticating with Twitter */ // initialize proxy var proxy = new OAuthProxy(CONSUMER_KEY, CONSUMER_SECRET, URL_FORMAT, false); // request token try { proxy.request_token("oauth/request_token", "oob"); } catch (Error e) { stderr.printf("Couldn't get request token: %s\n", e.message); return 1; } // prompt user for pin stdout.printf("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", proxy.get_token()); string pin = stdin.read_line(); // access token try { proxy.access_token(FUNCTION_ACCESS_TOKEN, pin); } catch (Error e) { stderr.printf("Couldn't get access token: %s\n", e.message); return 1; } /** sending the tweet */ // setup call ProxyCall call = proxy.new_call(); call.set_function(FUNCTION_STATUSES_UPDATE); call.set_method("POST"); call.add_param(PARAM_STATUS, args[1]); try { call.sync(); } catch (Error e) { stderr.printf("Cannot make call: %s\n", e.message); return 1; } // print success stdout.printf("Tweet succeeded!\n"); return 0; } }