5 Minutes to Social Android Apps with Singly

NOTE: This post is quite old now and Singly’s APIs have changed a good deal since. This post is here for posterity but many of the code examples no longer work or are applicable.

Full Disclosure I now work for Singly doing android development.

Singly provides a single API to access social data across multiple services. For app developers this means you can drop in the Singly Android SDK into your app, call a few methods, and just like that you have your user’s social data from Facebook, Twitter, Foursquare, and others services. Singly handles the authentication of your users with each service and gives you a consistent API to call to retrieve social data.

In this post I wanted to go into just how easy it is to create social Android apps using the new Singly Android SDK. This post assumes you know how to create Android projects in eclipse and how to import existing projects. We will go through three steps:

  1. Register with Singly to get API keys
  2. Download the Singly Android SDK from Github
  3. Use the Singly Android SDK in your app

Register with Singly to get API keys

First go to the Singly Login Page and use either your github account or your facebook account to login. Once authenticated you will be taken to the Singly Apps Page. Click the link that says “Default Singly App” under your applications. We will use the default for now. Later your can create your own apps and register that apps with the various services. The default app page will show your client id and client secret. Copy those two keys, we will need then in a bit.

Download the Singly Android SDK from Github

Now go to Github to the Singly Android SDK project. The SDK is all open source. You can clone the project to your local system using the following command.

In the SDK there are two folders, an sdk folder and an examples folder. You can import each folder as a project into eclipse using the “Import Existing Projects” eclipse menu item. This should setup two projects, one called SinglyAndroidSDK that is an Android library project that holds the SDK, and one called SinglyAndroidExamples that holds example applications.

Download Dependencies

The Singly Android SDK requires the Facebook Android SDK. Go to Github to the Facebook Android SDK project. You can clone the project into the same parent directory as the Singly Android SDK using the following command.

When downloaded into the same parent directory as the Singly Android SDK the Facebook Android SDK is automatically linked in as an Android Library project. It you downloaded it to a different directory you will need to link the Facebook Android Library to the Singly Android SDK project in eclipse.

Setting up the AndroidManifest.xml

You will then need to register a few activites and permissions in the AndroidManifest.xml file for your app. First register permissions. The Singly Android SDK will need to access the internet, network state, and write to internal storage.

Next register the activities used when calling authenticate on the SinglyClient. These are required.

And finally if using any of the Singly components you would also need to register those activites. For example if using the Authenticated Services component you would need to register its activity in your AndroidManifest.xml file.

Use the Singly Android SDK in your app

To use the SDK in your app you would first create a SinglyClient class like this, pasting in your client id and client secret from the default app you created earlier.

Once you have the SinglyClient you can have your user’s authenticate to multiple services (i.e. facebook, twitter, foursquare, github, and about 20 more) by calling the authenticate method of the SinglyClient and passing in a service name. Your user’s should only have to authenticate with each service once for you to access data from that service. To call singly apis your users only need to authenticate with a single service.

The authentication process will launch a dialog with a web view that allows the user to authenticate with the service through oauth. You can pass in an AuthenticationListener class to receive callbacks at various stages of the process. For example once the user has authenticated the onAuthenticated method will be called.

Using the SinglyClient class you can have your user authenticate to any Serivce Singly Supports. Once authenticated you can make api calls into the Singly API to get data.

You can use the apiCall method to call into any Singly api and get your user’s data from any service they have authenticated with. Take a look at the Singly API Explorer to see all the different calls that can be made and data that can be retieved.

Conclusion

And that is it. That is all it takes to get social data into your Android application. Quick and easy.

If you want to see some examples run, paste your client id and client secret into the MainActivity and ProfilesActivity classes in the example app in the SinglyAndroidExamples project. Then run app. The example shows authentication with different services and making api calls into the Singly api.

If you are in the Chicago area on September 29-30 2012, Singly and Braintree are Having a Hackathon. Come and build an Android app using the new Singly Android SDK.

5 thoughts on “5 Minutes to Social Android Apps with Singly

  1. It’s a shame this relies on a webview and not the respective native SDKs. Asking a user to input their email and password for facebook where they already have that information persisted in the Facebook Android will cause more friction to registration.

    1. We will be adding in native authentication through the facebook app as well as other apps if the user has them installed. The web view was a first step and also a fallback in that not all apps (twitter I am looking at you) allow native authentication.

Comments are closed.