API Description: http://open.t.sohu.com/
Development support: Openapi@sohu-inc.com
Below is an example program that is debugged on a laptop.
If you want to make a BlackBerry version, the code might be a little more complicated. But the same principle, is to go to the HTTP protocol post Weibo data to Sohu.
Dependency Class Library: Commons-codec-1.3.jar,commons-httpclient-3.0.1.jar,commons-logging-1.1.jar
public class Sohublogger {
HttpClient client = new HttpClient ();
String server_update = "Http://api.t.sohu.com/statuses/update.xml";
String USERNAME =cafebabe@xxx.com;
String PASSWORD = "xxx";
public static void Main (string[] args) {
Sohublogger controller = new Sohublogger ();
try {
Controller.postmessage ("Hello World Chinese");
} catch (HttpException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
}//
public void PostMessage (String msg) throws HttpException, IOException {
Base64encoder decoder = new Base64encoder ();
msg = Decoder.encodebuffer (msg.getbytes ("UTF-8"));
Boolean needauthentication = true;
if (needauthentication) {
Client.getparams (). Setauthenticationpreemptive (True);
Client.getstate (). SetCredentials (
New Authscope (Authscope.any_host, Authscope.any_port, Authscope.any_realm),
New Usernamepasswordcredentials (USERNAME, PASSWORD));
}
Postmethod method = new Utf8postmethod (server_update);
if (needauthentication) {
Method.setdoauthentication (TRUE);
}
Method.addparameter ("status", msg);
Client.executemethod (method);
System.out.println ("Post status:" + Method.getstatusline (). toString ());
System.out.println ("Post page content:"
+ method.getresponsebodyasstring ());
Release any connection resources used by the method
Method.releaseconnection ();
}
}