4
votes

I'm adding social integration to my app, and am looking for general advice how to go about it.

At the moment the app is showing feed of particular Facebook wall (authentication handled by Facebook's Android SDK) and feed for particular Twitter hashtag. That's a start, but I want these feeds to do a bit more. For Facebook:

  • For long feed items, user should be able to "see more", including linked pictures
  • Links inside feed items should work and open in browser
  • Like/unlike feed items
  • Comment on feed items
  • Post on the wall (create another item in feed)

Similarly, for Twitter:

  • Links inside tweets should work and open in browser
  • Reply to, and retweet tweets
  • Create tweets that contain the specific hashtag

Since Facebook and Twitter both have comprehensive APIs and there are enough code samples floating around, this is all technically doable, but seems a lot like reimplementing Facebook and Twitter clients. That's a lot of work to get all the little details right, maintain code for API changes, and not really in the scope of my app.

So I'm thinking how to avoid reimplementing Facebook and Twitter clients.

Idea one: direct user to mobile versions of the respective sites and be done with it. Downside is that user will have to go through cumbersome authentication, even if there are dedicated client apps already installed and authenticated on user's device.

Idea two: plug into existing apps using intents system: if official Twitter app is installed, use that to do hashtag search. If Seesmic or Twidroid or some other twitter client is installed, use that. As a fallback, open Twitter's mobile website in browser. Similar for Facebook. Downside here is that intents for "show facebook stream" or "search tweets for X" are not standartized. Most current apps don't even have documented ways to plug into them. Using undocumented entry points in those apps is possible but would make my app hacky and brittle.

So, this question, how you've been dealing with integrating bits of Facebook and Twitter functionality in your apps, or seen done by others?

3

3 Answers

2
votes

Here is a good tip about how to implement twitter/facebook oauth:

  1. Create new activity and name it OAuthActivity.
  2. Create new class that extends WebView.
  3. Follow the facebook developer guide for WEB applications (not mobile ones!) and implement oauth calls inside of your WebView. For Twitter use Signpost-core with signpost-commonshttp4 to get oauth (facebook uses its own variation of oauth so you need to do it yourself).
  4. Override WebView so it closes itself when facebook redirects your WebView subclass to your callback url.
  5. Use OAuthActivity to return OAuth key / secret to your main activity via RunActivityForResult.

This way screen orientation change will work; you will have same architecture for FB and TW.

I have implemented it this way, yet I can not share my code (it is licensed for my company).

1
votes

When I added Facebook and Twitter integration into my app (shameless plug: Secret Message), I attempted to invoke an installed Twitter client app via Intent. It wasn't fun, because there is no such thing as a "facebook/text" or "twitter/text" Intent. I know some Twitter apps create their own, but they're not universally used or even known.

So the other option is to get a list of all installed apps and filter on those you want to display in a chooser for the user to select. But retrieving a list of packages and their user-friendly names takes forever. So I hated that option.

I ended up integrating a very simple GUI for both Facebook and Twitter into my own app, and just used OAuth to authenticate users.

I hope this helps you pick your direction.

1
votes

implementing Twitter integration is pretty easy on Android (you can use Twitter4J which is a pretty nice Twitter Java Library to access the public web services).

To integrate tweeting/retwreeting is basic stuff once you have authenticated your twitter user (just have a text box to allow users to enter thei 140 characters and a button to submit it - creating tweets, retweeting, replying etc is all a matter of 1 or 2 lines of code using twitter4J). The link stuff requires formating your listview to handle weblinks and open as appropriate.

The toughest part of the whole twitter integration thing is getting the OAuth stuff done - there is a tutorial on how to implement twitter and the OAuth authentication stuff here

Unfortunately, I have never tried facebook integration, but hopefully someone will be able to help out with that.