This document presents an example of how to use Facebook's GraphAPI in Smart Device applications using GeneXus.
You must register your application on the Facebook developer site and get your Facebook App Id.
Refer to HowTo: Register a Facebook App for Smart Device interaction for detailed information.
Use SD Facebook Button control to allow the end user to log in to the GeneXus app using Facebook's credentials. This action will allow you to get the user's Access Token and use the Graph API for retrieving user data.
For example, you can use the OnUserInfoUpdated event and request the access token as follows:
&FacebookAccessToken = Facebook.AccessToken
where &FBAccessToken is based on FacebookAccessToken SDT.
In this case, we will use the Graph API for getting the user's posts. To do so, the developer must ensure that "user_posts" tag is added to Read Permission property. When the end user logs in, Facebook will inform him/her about your purpose (in this case, get his/her posts).
Write an online Procedure for requesting the GraphAPI data by using HttpClient data type. This procedure should receive in its parm rule the access token and user identifier strings obtained from the device.
For example, suppose the procedure is called GetUserPosts, and it has defined the following parm rule:
parm(in:&AccessToken, in:&UserId, out:&FBJson);
You can write a source code as follows:
&FBVersion = !"v2.12" // Change it if it is necessary
&Url = !"https://graph.facebook.com/%version/%user_id/feed?access_token=%access_token"
&Url = &Url.Replace("%version",&FBVersion)
&Url = &Url.Replace("%user_id",&UserId)
&Url = &Url.Replace("%access_token",&AccessToken)
&FBJson = &HttpClient.ToString()
Then, in a user event, you can invoke this procedure as follows:
Event 'Get My Posts'
&FBJson = GetUserPosts(&FacebookAccessToken.AccessToken, &FacebookAccessToken.UserId)
As a result, after the user has logged in, the &FBJson string-based variable will have the following value:
"story": "Damian Salvia is with Pablo Martinez and 5 others.",
"story": "Stella Marys Pereira Larrosa added a new photo \u2014 with Nicolas Mechulam and 2 others.",
It's your responsibility to parse the result to meet your requirements.
Full Graph API integration is available as of Genexus 15 Upgrade 10.