Medium_icon

Simple Application

This tutorial shows you how to get started using LocalSocial and walks you through the very initial elements you need to use in the LocalSocial Library on Android, and in the LocalSocial API. For obvious reasons, this is called the Simple Application, and the source code is available.

Download the Source Code

This source code shows you how to get started using LocalSocial and walks you through the very initial elements you need to use in the LocalSocial Library on Android, and in the LocalSocial API.

Download Source

LocalSocial Configuration

The first step involved in using LocalSocial is to configure the Client application to access the LocalSocial Service. The Client application must provide an instance of the com.localsocial.LocalSocial.AppConfiguration interface. The mandatory configuration parameters are:

  1. the Service Name, “Simple” in this case. This is your name for the service you are developing.
  2. the consumer secret, the OAuth consumer secret that was generated when you registered your application.
  3. the consumer key, the OAuth consumer key generated when you registered your application

Note: You must keep your consumer details secret.

LocalSocial provides an implementation of this interface called com.localsocial.config.SimpleAppConfiguration. Once created, this AppConfiguration object must be given to LocalSocial with to the LocalSocialFactory.setDefaultConfig.

For example , SimpleApp defines a method called bootstrap(). This method is called from the Android onCreate method. When bootstrap() completes then you can access the LocalSocial object instance. However, as we'll see in the next section, you may need to authorise your application before you can access LocalSocial Remote services.

LocalSocial Authorisation

Once you have bootstrapped LocalSocial in your client application, you can now load an existing OAuth Access token for your client or generate a new one. This access token is then used to access the LocalSocial service.

The steps involved in authorising the application are:

  1. Attempt to load an existing Access Token
  2. if this fails then
    1. Generate a new Request Token
    2. Authorise the Request Token. It's good practise at this point to display a message to the user asking them to click a button to authorise the token
    3. Exchange the authorised Request token for a new Access Token
    4. Store the Access Token in the LocalSocial configuration

Tag CRUD

Now that you have ensured that LocalSocial has a valid access token, you can access your tags and create or update tags. This is easily accessed through the com.localsocial.remote.TagRemote interface.

To dump out all the tags associated with current device and namespace:

Although the simple app doesn't show deleting a tag, this can be easily done with the following sample code:

Note: In general these operations should not be performed in the UI thread of your application as they can take some time to complete. For example, on android, you should use an AsyncTask to execute these operations. See any of the sample applications for an example of this approach