Javascript based Facebook login OAuth 2.0
One of the positive features of OAuth 2.0 is that the OAuth dance occurs only by using HTTP GET method. This code resides in the Auth.htm page. The if structure checks the browser URL to identify the current step and move to the next one. The first step is to access the https://www.facebook.com/dialog/oauth by providing the application id, the redirection URI and the response type (which in our case is of type token). In our case we set the redirection address to again to the Auth.htm file. After the successful redirection from the Facebook page the script makes again a HTTP GET request to the same endpoint by providing the application ID, redirect URL, the response type and the resources that this application will have access to. If everything goes well then Facebook redirects the browser to back to the Auth.htm page by providing a code parameter. The final part of the script extracts this information for the url and passes it to our servlet in order to provide a customized to the user homepage (e.g. his profile image etc.).
31 } |
Java2htm |
Check in on Facebook
The following code snippet is a Java Servlet code that uses an HTTP GET method to access the https://graph.facebook.com/me/checkins endpoint. For the successful invocation we must provide a message, an access_token, the placeID of the place where the movie was watched, the friends ids they are also watching the movie and the coordinates of the check in place. Another important part on this code is the multipart/form-data mime type. This is the only content type supported by Facebook. Finally the DataOutputStream and the InputStream handles the HTTP request and response respectively.
31 rd.close(); |
Java2html |
Check in on twitter
Twitter integrates the check in functionality on twitters (it is not a separate task like facebook). This means that the only we have to do is to make a post and provide in addition the geolocation information. In the figure below is the Java servlet code that does exactly that by employing the Scribe-Java library.
26 } |
Java2html |