开发者

how to use twitter api in android application for send tweet only

i want to know 开发者_如何学运维about twitter api for android application.... please send me link or source for twitter api which api just only for send the tweet....


String tweetUrl = "https://twitter.com/intent/tweet?text=PUT TEXT HERE &url="
                    + "https://www.google.com";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));

For more info, check my answer on this other post

How to tweet from Android app?


To share some text using standard android intents, only three lines of code are necessary. The user will be prompted to pick a method (and they can then choose Twitter.)

    Intent share = new Intent(Intent.ACTION_SEND);
    share.putExtra(Intent.EXTRA_TEXT, "Here's some text for Twitter.");
    startActivity(Intent.createChooser(share, "Share this via"));

If you want to do more advanced stuff with Twitter:

I found that a lot of the solutions posted on the Internet were needlessly complicated. For me, it was only a couple additional lines of code beyond what Twitter4J tells you to do.

For my dollar, Stephan's answer here is the best.

I have some example code on github using his technique, here.


Code :

protected String doInBackground(String... args) {

          ConfigurationBuilder builder = new ConfigurationBuilder();
          builder.setOAuthConsumerKey(CONSUMER_KEY);
          builder.setOAuthConsumerSecret(CONSUMER_SECRET);
          AccessToken accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
          Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
          try {
      twitter4j.Status response = twitter.updateStatus(tweetText);
      return response.toString();
    } catch (TwitterException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
       return null;
       }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜