Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post message on twitter wall using twitter integrate android app

I would like to integrate Twitter into my Android application so that I can post messages to Twitter.

like image 542
Narasimha Avatar asked Dec 22 '22 18:12

Narasimha


2 Answers

You could use the twitter4j library to talk to twitter. Since Twitter has changed over to oAuth, the initial authentication is not trivial.

Basically you need to register your app with Twitter (go to your profile and then to the developer page to register your app - you will then get consumer token+secret). Then follow this example to authenticate with Twitter.

You may have a look at Zwitscher (rev 0.65, code of oAuth has not been updated for the nw internal changes after 0.65), which is an open source Twitter client for a larger example.

like image 35
Heiko Rupp Avatar answered May 14 '23 12:05

Heiko Rupp


It really depends on how you want the interaction to work. You can:

  1. Use their API (helped by a library such as twitter4j, as suggested by Heiko Rupp), or
  2. Find a way to integrate with the Twitter app, although there is no published protocol for this as far as I know. This is also not a good idea because many people use other apps such as Twidroyd, TweetDeck and so on, but it would definitely be cool, or
  3. If you don't expect the user to do this very often, you can just open up http://twitter.com/?status=<what-to-tweet> using a simple intent.

Method 3 can be easily described here:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://twitter.com/?status=" + Uri.encode(message)));
startActivity(i);

You can also combine 2 and 3. You can try a few known apps (official Twitter, TweetDeck, ...) and if all of them fail (because they're not present or because they have been updated and broke the protocol) you resort to opening up the browser.

Also note that it might be possible for method 3 to actually launch an app instead of the browser (or at least give the user a choice between the two), if the app handles the correct intents.

Another thing worth mentioning is that it's very possible that you will not be able to integrate with any Twitter apps. What I've said here is purely hypothetical, I have no idea whether these apps support such integrations. You should consult each app and see if they expose some intents that you could use. If they don't, you can still hack around a little and you might find them, but that will be unreliable because they will most probably break after a couple of updates.

like image 153
Felix Avatar answered May 14 '23 11:05

Felix