|In this article, I’m going to show you how you can use Foursquare in your Android application using OAuth 2.0.
We’ll be using
I’ve decided to use the foursquare-api-java, a project hosted at Google Code, as it offers a rich interface to interact with Foursquare. The same API calls are possible through the Google API client for Java, but it would require you to write your own model classes to do the JSON to Java translation.
In the sample application hosted at Github, we’re going to display a map where the user can select a location. Upon selecting a location, we’ll load up a list of Foursquare venues that the user can select.
|A couple of months ago, I published a post entitled A 30 minute guide to integrating Twitter in your Android application.. The post presented a sample Android application to integrate Twitter. Using the signpost library, the user was able to authorize our application to send tweets on his/her behalf. It seems that everyone is migrating to Oauth 2.0, but Twitter is still stuck at OAuth 1.0. Nevertheless, I still wanted to update the sample we did a couple of months ago for 3 reasons :|
|In this article, I’m going to show you how you can implement an OAuth 2.0 flow in Android.
We’ll be using
In the sample application, we’re going to execute 1 authorized API call to the Latitude API. The call will return the current location of the user.
|As mentioned in the Facebook developer docs, test users can only be created using a call to the Graph API.
As described in my previous Facebook article, a dedicated webpage was available at the time to create test users, however, that page has been brought offline.
You can create a test user associated with a particular app using the Graph API with your app access token.
https://graph.facebook.com/APP_ID/accounts/test-users? installed=true &permissions=read_stream &method=post &access_token=APP_ACCESS_TOKEN
However, before we’ll be able call this API, we first need to retrieve an Access Token for our application.
|Today we’ll be looking at the Google APIs Client Library for Java. The API is provided by Google, and is a flexible, efficient, and powerful Java client library for accessing any HTTP-based API’s on the web. According to Google, it is the recommended library for accessing Google API’s based on REST or JSON-RPC. One of the nice things about this library is that it fully supports the Android environment out of the box. So we’ll focus on those features in this article.|
To avoid confusion, Google offers the following APIs (the first one being the topic of this post, and compatible with the Android platform) :
- Google APIs Client Library for Java (google-api-java-client)
- Google Data Java Client Library (gdata-java-client)
Unfortunately, there are no samples available that perform the OAuth dance in Android using this library, so I thought I’d write one myself. The code for this article can be found in the AndroidOauthGoogleApiJavaClient repository
Continue reading “OAuth in Android using the Google APIs Client Library for Java” »
|The goal of this article is to get Facebook integration up & running from your Android app in 30 minutes. The guide will show you how to
This guide is accompanied by a sample application that’s available in Github in the AndroidFacebookSample repository. To import this project in Eclipse, I suggest using the EGit plugin that can be installed via the Main P2 Repository located at http://download.eclipse.org/egit/updates.
Before running this project, make sure you change the com.ecs.android.facebook.Sample.AndroidFacebookSample file to include your Facebook API key (see subsequent section).
Once you have sample application up & running, you can copy the relevant classes into your projects to have Facebook up & running from your Android application.
First things first … In order to integrate with Facebook, you need 2 things :
- A Facebook test account, used in our Android application to login to Facebook and make status updates.
- A Facebook application, used to inform the user in your Android application that this application is requesting you to login to Facebook.
Important note : As an update to this article, I’ve prepared a new post entitled Improved Twitter OAuth for Android focussing on a more simple Oauth / Android experience, and using the Google APIs Client Library for Java.
The goal of this article is to get twitter integration up & running from your Android app in 30 minutes. The guide will show you how to
This guide is accompanied by a sample application that’s available in Github in the AndroidTwitterSample repository. To import this project in Eclipse, I suggest using the EGit plugin that can be installed via the Main P2 Repository located at http://download.eclipse.org/egit/updates.
Before running this project, make sure you change the com.ecs.android.sample.twitter.Constants file to include your consumer key and consumer secret. (see subsequent section).
Once you have sample application up & running, you can copy the relevant classes into your projects to have Twitter up & running.
Twitter uses the OAuth protocol to authorize your android application to send tweets on behalf of the end-user. The end-user will need to authenticate against Twitter (meaning that your application will not capture the twitter username / password). Once the user has authorized access, you’ll be able to send tweets on behalf of the user. We’ll use signpost library to handle the OAuth communication, and the Twitter4J library to handle the Twitter specific interactions (sending tweets).
|In this post, I’ll be showing you how to use the OAuth signpost library in an Android application. We’ll create a simple application that fetches your Google Contacts using the Google Contacts API, and display the contact names on the screen.
We’ll focus on using the Signpost API in an Android runtime, and implementing the OAuth workflow from the first step (requesting a request token) till the final API call with our access token. We’ll glue the entire OAuth workflow together in our Android application, using different techniques offered by the Android platform. As you can see from the screenshot below, it’s not the most aesthetically pleasing application, but it gets the job done.
|For a quick command line java example, we’ll be using the oauth-signpost library, a java library with OAuth support that can also be used in Android projects (see Implementing the OAuth flow in Android) . The sample code below illustrates how easy it is to orchestrate the OAuth workflow from a java runtime. The sample program will use a command-line approach guiding you to the oauth flow. It will basically do the following steps :
|After having an overview of OAuth, we can now get a change to watch the OAuth dance unfold before us with a great site called the OAuth Playground where we can simulate all these OAuth requests. The site allows us to see the HTTP requests behind the OAuth workflow we discussed in the previous section. For the sake of this example, try to think of the OAuth playground as a rich application where you can view your Google contacts. (Obviously, OPlayground is a technical oriented site, allowing you to see the different request on the HTTP level, but the same principles apply.|