2012年3月26日 星期一

Titanium Mobile - Facebook Graph

Introduce how to call facebook graph api in Titanium Mobile Project

There have two way using it, direct link or use Titanium.Facebook.requestWithGraphPath

For more info about the detail of Facebook Graph API please see the official site here

I will also list some api call example below
First,use direct link

[wp_ad_camp_2]


U should call link with this format https://graph.facebook.com/ID/CONNECTION_TYPE?access_token=ACCESS_TOKEN,

ID can get from facebook, e.g userid & fanid & photoid & albumid & statusid...

CONNECTION_TYPE is the things that we want to get, e.g our posts/albums/videos or status comments/likes and many things u want

ACCESS_TOKEN can get from Titanium.Facebook.accessToken

REMEMBER!!!!To USE FACEBOOK GRAPH API NEED TO LOGIN!!!

now, we know the graph api link structure so that we can get our data, but we still need a function to get the result back, below has a sample about the function
[gist]http://gist.github.com/2198318[/gist]

than, call the function use the format below because of the callback, or change to whatever u want if u know how to use
function(graph link,function(data){
data.@Y&#
});
Second, Titanium.Facebook.requestWithGraphPath to POST

u can use it to post status comment or post a new status also can get data like above,
below show's example
[gist]http://gist.github.com/2198518[/gist]
ID if u would like to post a new status the ID must be ur userid or simple use 'me', and for comment a status the ID should be the status' ID
CONNECTION_TYPE for post to wall use '/feed' or comment use '/comments'

now,just enjoy code with facebook!

BTW, we also can use graph api to search things like places(the checkins),if u want to call don't forget to take a look at official document here

[wp_ad_camp_1]

0 意見:

張貼留言