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.
Documentation » Tutorials
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.
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:
- the Service Name, “Simple” in this case. This is your name for the service you are developing.
- the consumer secret, the OAuth consumer secret that was generated when you registered your application.
- 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.
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:
- Attempt to load an existing Access Token
- if this fails then
- Generate a new Request Token
- 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
- Exchange the authorised Request token for a new Access Token
- Store the Access Token in the LocalSocial configuration
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