7

In my app I need to share link for promo site via Facebook and twitter, in facebook we got something like "share dialog" or post bundle like

Request request = new Request(Session.getActiveSession(), "me/feed", bundle, HttpMethod.POST, 
       new Request.Callback(){
                @Override
                public void onCompleted(Response response) {
                    ...
                }
            });

but there are no twitter sdk for android(trully I use twitter4j) and no way to post bundle

so how to tweet link via twitter?

user2331879
  • 143
  • 1
  • 5

3 Answers3

2

If you send text with link like "Here is our link: http://stackoverflow.com" - twitter will understand it and get info from your link and show it - as I understand you need to see your recognized link in twitter feed. To post link you can make intent like @Adrian Sicaru or create your own custom dialog using asynctask with twitter4j as you mention:

@Override
protected Bundle doInBackground(Bundle... params) {
    Bundle args = params[0];
    Bundle result = new Bundle();

    String paramMessage = args.getString(MESSAGE);
    String paramLink = args.getString(LINK);

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey("your ConsumerKey");
    builder.setOAuthConsumerSecret("your ConsumerSecret");

    String accessToken = "your Token";
    String accessTokenSecret = "your Secret";

    TwitterFactory factory = new TwitterFactory(builder.build());
    mTwitter = factory.getInstance(new AccessToken(accessToken, accessTokenSecret));
    try {
        StatusUpdate status = new StatusUpdate(paramMessage);

        if (paramLink != null) {
            status = new StatusUpdate(paramMessage + " " + paramLink);
        }
        mTwitter.updateStatus(status);
    } catch (TwitterException e) {
        result.putString(RESULT_ERROR, e.getMessage());
    }
    return result;
}
1

You can do it via intent like this :

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

This will open a list with apps already installed that can answer the intent, like gmail, facebook and... twitter.

You can find more information here: http://developer.android.com/training/sharing/send.html

Also, if you want to directly call twitter and don't want to choose, have a look at this answer

Community
  • 1
  • 1
Adrian Sicaru
  • 1,042
  • 1
  • 9
  • 20
1

Like @TribblerWare answered just write link in tweet and twitter recognized it.

By the way, you can use ASNE library for this - just authorize user and use requestPostLink with bundle as parameter

Bundle postParams = new Bundle(); 
postParams.putString(SocialNetwork.BUNDLE_LINK, link); 
socialNetwork.requestPostLink(postParams, message, postingComplete);

more detailed you can see in tutorial

Seko
  • 620
  • 9
  • 18