开发者

Sending tweets using Android

开发者 https://www.devze.com 2023-01-03 21:44 出处:网络
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/

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号