Can anyone tel me how to tweet using An开发者_JAVA技巧droid? How can i send tweets using Android?
Check the API available at http://apiwiki.twitter.com/
There is a list of FAQs and examples available there.
You want something like this:
mHttpClient = new DefaultHttpClient();
mCredentials = new UsernamePasswordCredentials("username", "password");
mHttpClient.getCredentialsProvider().setCredentials(
new AuthScope("twitter.com", 80, "Twitter API"),
mCredentials);
HttpPost post = new HttpPost("http://twitter.com/statuses/update.xml");
HttpParams params = post.getParams();
HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY);
HttpProtocolParams.setUseExpectContinue(params, false);
post.setParams(params);
ArrayList<NameValuePair> form = new ArrayList<NameValuePair>();
form.add(new BasicNameValuePair("status", "I'm tweeting!"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(form);
post.setEntity(ent);
HttpResponse resp = mHttpClient.execute(post);
(Ripped from my own code, and stripped down a little bit for brevity. It won't compile as-is!)
Here's an example of how to develop a twitter client for android.
If you just want to send tweets from Android and not necessarily from your application you could try andtweet.
精彩评论