开发者

What is the simplest current example of how to update your twitter status from an Android Application?

What is the simplest开发者_Python百科 current example of how to update your twitter status from an Android Application?


Although the actual code to send a tweet is simple using the Twitter4J library in Android :

public void sendTweet(SharedPreferences prefs,String msg) throws Exception {
    String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
    String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");

    AccessToken a = new AccessToken(token,secret); 

    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
    twitter.setOAuthAccessToken(a);
    twitter.updateStatus(msg);
}

However, a lot of preperation is needed before you'll be able to succesfully execute these calls.

Take a look at a 30 minute guide to integrating Twitter in your Android application that covers all steps required to tweet from an Android app :

  • setup a twitter test account
  • register a twitter application
  • authenticate the user in your Android application using OAuth
  • have the user send tweets from your Android application using the Twitter4J library

A sample project is included in the AndroidTwitterSample GitHub repository to get you started.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜