by ScottGeek
16. August 2009 20:51

How about some Java?
import sun.misc.BASE64Encoder;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStreamWriter;
import java.net.URLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class Twitter {
public static void main(String[] args) throws Exception {
if (args.length < 3) {
System.out.println("Twitter <userid> <password> <message>");
System.exit(-1);
}
URL url = new URL("https://twitter.com/statuses/update.xml");
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
String authorization = args[0] + ":" + args[1];
BASE64Encoder encoder = new BASE64Encoder();
String encoded = new String
(encoder.encodeBuffer(authorization.getBytes())).trim();
connection.setRequestProperty("Authorization", "Basic " + encoded);
OutputStreamWriter out = new OutputStreamWriter(
connection.getOutputStream());
out.write("status=" + URLEncoder.encode(args[2], "UTF-8"));
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String response;
while ((response = in.readLine()) != null) {
System.out.println(response);
}
in.close();
}
}
Some nice stuff….
~cse
Related posts
Share on TwitterInteresting piece of code. I haven’t gotten into Twitter’s API yet… but he’s some sample code that w...OMG…More Twitter Code?Nope haven’t gone all twitter manic…
If you have a bit.ly account (free) y...Re-posting stuffWell, time to repost....that is if LiveWriter will work... ~cse
Powered by BlogEngine.NET - Modified by cse 1.5.0.7
Theme by Extensive SEO Modified by cse
Content on these pages are my thoughts and ideas and are by statement under US Copyright(C) CSE. If you borrow my words, Give Credit!
Under no condition whatsoever do my Words, Thoughts, Opinions, Comments, or Statements reflect those of any Person, Company, Nation, or Living Creature
upon this Planet or any other Planet in the known Universe or any Parallel Universe whether currently in existent or not. As such, I do not make warrenty
as to anything written in the content of these pages. Use at your own risk!