How to share a link via twitter in android?

In my application I need to share a link to a promo site via Facebook and twitter, on facebook we got something like a “sharing dialog” or a message bundle like

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

but for android there is no twitter sdk (trully I use twitter4j) and cannot send a message

so how to tweet the link via twitter?

+7
android twitter
source share
3 answers

If you send text with a link like "Here is our link: /fooobar.com / ... " - twitter will understand this and get the information from your link and show it - as I understand it, you need to see your recognizable link on Twitter. To send a link, you can do it like @Adrian Sicaru or create your own dialog using asynctask with twitter4j, as you mentioned:

 @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; } 
+2
source share

You can do this with this type:

 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 already installed applications that can respond to the intent, for example 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 on Twitter and don’t want to choose, see this answer

+1
source share

Like @TribblerWare, it only responded to a link to tweet and Twitter recognized it.

By the way, you can use the ASNE library for this - just log in the user and use requestPostLink with the package as a parameter

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

in more detail you can see in the textbook

+1
source share

All Articles