sam_k
sam_k

Reputation: 6023

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....

Upvotes: 17

Views: 37925

Answers (3)

Dmarp
Dmarp

Reputation: 228

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;
       }

Upvotes: 0

gian1200
gian1200

Reputation: 3864

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?

Upvotes: 25

Jameson
Jameson

Reputation: 6669

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.

Upvotes: 3

Related Questions