Use of Titanium Facebook Graph API with helps of Facebook Graph Explorer

Facebook Graph Explorer provides useful tool helps developers to test it out the Graph API easily by issuing a REST-liked Request URL, HTTP Method (GET, POST, DELETE) to query or posting to the Facebook Objects.

Titanium mobile is a development platform to develop native mobile apps using JavaScript API.

Titanium mobile has delivered built-in Facebook APIs that greatly helps developers to integrate their mobile apps with Facebook. The Titanium Facebook API supports issuing an old REST API or a new Graph API to interact with Facebook Platform.

I tested out Facebook Graph Explorer and found that it is very helpful that guided me in a straight way to issue Titanium Facebook Graph API to query the Facebook Pages feeds, posting feeds and the posting feeds comments on behalf of user.

I had written a snippet of code in order to prove that it is worked.

Titanium Mobile JS Code:


var win = Ti.UI.currentWindow;
Titanium.Facebook.appid = "70518428114";
Titanium.Facebook.permissions = ['publish_stream', 'read_stream'];
Titanium.Facebook.requestWithGraphPath('70518428114/feed', {message : 'I love you my angels'}, 'POST', function(e) {
var result = e.result;
result = JSON.parse(result);
var newid = result.id;
Ti.Facebook.requestWithGraphPath(newid + '/comments', {message : 'I love you too darling'}, 'POST', function(ce) {
alert("Had made a Facebook comment");
});
});

The Titanium code above is trying to publish a feed on a page using Titanium Facebook Graph API, and then the result of new feed ID is returned which used for the next Graph API request to create a comment for that feed.

In the function Titanium.Facebook.requestWithGraphPath, we provide first parameter as the graph URL request, followed by the data to be passed by, and then to specify the HTTP method parameter (GET, POST, DELETE), and then followed by the callback parameter which JSON result will be returned. You can use these three HTTP method parameter to issue request to same graph URL request to perform different thing, such as to use GET to query out the list of data, to use POST to insert or update data, and to use DELETE to delete the data. It is REST-ful.

iPhone Simulator Print Screen showing the alert message:

iPhone Simulator showing alert box after Facebook Comment created

Facebook Print Screen showing the Facebook feeds and comments had been posted by Titanium Facebook Graph API.

(Click the thumbnails to see full image preview)

Conclusion

Facebook Graph Explorer greatly helps developers to test it out the Facebook Graph API and Titanium mobile had delivered its simple-to-use Facebook API module that made integration of our mobile apps to Facebook Platform become very easy.

Author: fyhao

Jebsen & Jessen Comms Singapore INTI University College Bsc (Hon) of Computer Science, Coventry University

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.