If you don’t want to use the App42 User service and already have your users with Facebook, you have to integrate Facebook with your App. Facebook SDK should be used to perform user authentication in this case. Successful user authentication from Facebook will return an access token that can be used to access social APIs of App42. See Facebook Login Docs for more details about integrating Facebook SDK with respective platforms and fetching the user access token.
Once you have authenticated your user you have to call link user method available in our social service and pass the access token along with the user name. Here your user name should be your user Facebook id received in Facebook OAuth/login response. You have to use Facebook user id in all App42 API calls wherever username parameter is required in method calls. See How to get Facebook User Id from access token.
Once your app user OAuth with Facebook is done using the Facebook SDK, you can link Facebook users with App42 using the snippet given below -
Here username must be passed as Facebook user id.
String userName = "<Facebook User Id>"; String accessToken = "FACEBOOK ACCESS TOKEN"; socialService.linkUserFacebookAccount(userName, accessToken, new App42CallBack() { public void onSuccess(Object response) { Social social = (Social)response; System.out.println("userName is " + social.getUserName()); System.out.println("fb Access Token is " + social.getFacebookAccessToken()); String jsonResponse = social.toString(); } public void onException(Exception ex) { System.out.println("Exception Message"+ex.getMessage()); } });NSString *userName = @"<Facebook User Id>"; NSString *accessToken = @"FACEBOOK ACCESS TOKEN"; Social *social = [socialService linkUserFacebookAccount:userName accessToken:accessToken); NSLog(@"Username is %@",social.userName); NSLog(@"FacebookAccessToken is %@",social.facebookAccessToken); NSString *jsonResponse = [social toString];public class Callback : App42Callback { String userName = "<Facebook User Id>"; String accessToken = "FACEBOOK ACCESS TOKEN"; socialService.LinkUserFacebookAccount(userName, accessToken, this); void App42Callback.OnException(App42Exception exception) { Console.WriteLine("Exception Message"); } void App42Callback.OnSuccess(Object response) { Social social = (Social) response; Console.WriteLine("userName is" + social.GetUserName()); Console.WriteLine("fb Access Token is" + social.GetFacebookAccessToken()); String jsonResponse = social.ToString(); } }String userName = "<Facebook User Id>"; String accessToken = "FACEBOOK ACCESS TOKEN"; Social social = socialService.linkUserFacebookAccount(userName, accessToken); System.out.println("userName is " + social.getUserName()); System.out.println("fb Access Token is " + social.getFacebookAccessToken()); String jsonResponse = social.toString();var userName = "<Facebook User Id>", accessToken = "FACEBOOK ACCESS TOKEN", social ; socialService.linkUserFacebookAccount(userName, accessToken,{ success: function(object) { var response = JSON.parse(object); social = response.app42.response.social; console.log("userName is " + social.userName) console.log("fb Access Token is " + social.facebookAccessToken) }, error: function(error) { } });String userName = "<Facebook User Id>"; String accessToken = "FACEBOOK ACCESS TOKEN"; Social social = socialService.linkUserFacebookAccount(userName, accessToken); System.out.println("userName is " + social.getUserName()); System.out.println("fb Access Token is " + social.getFacebookAccessToken()); String jsonResponse = social.toString();String userName = "<Facebook User Id>"; String accessToken = "FACEBOOK ACCESS TOKEN"; App42Log.SetDebug(true); //Print output in your editor console socialService.LinkUserFacebookAccount(userName, accessToken, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { Social social = (Social) response; App42Log.Console("userName is" + social.GetUserName()); App42Log.Console("fb Access Token is" + social.GetFacebookAccessToken()); } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }String userName = "<Facebook User Id>"; String accessToken = "FACEBOOK ACCESS TOKEN"; Social social = socialService.LinkUserFacebookAccount(userName, accessToken); Console.WriteLine("userName is" + social.GetUserName()); Console.WriteLine("fb Access Token is" + social.GetFacebookAccessToken()); String jsonResponse = social.ToString();$userName = "<Facebook User Id>"; $accessToken = "FACEBOOK ACCESS TOKEN"; $social = $socialService->linkUserFacebookAccount($userName, $accessToken); Print_r("userName is" . $social->getUserName()); Print_r("fb Access Token is" . $social->getFacebookAccessToken()); $jsonResponse = $social->toString();N/AN/AN/A
Once you have linked your user, you can use Facebook id to share status on Facebook using the following snippet.
String userName = "<Facebook User Id>"; String status = "I am using the App42 API"; Social social = socialService.updateFacebookStatus(userName, status, new App42CallBack() { public void onSuccess(Object response) { Social social = (Social)response; System.out.println("userName is " + social.getUserName()); System.out.println("status is " + social.getStatus()); String jsonResponse = social.toString(); } public void onException(Exception ex) { System.out.println("Exception Message"+ex.getMessage()); } });NSString *userName = @"<Facebook User Id>"; NSString *status = @"I am using the App42 API"; Social *social = [socialService updateFacebookStatus:userName status:status); NSLog(@"Username is %@",social.userName); NSLog(@"status is %@",social.status); NSString *jsonResponse = [social toString];public class Callback : App42Callback { String userName = "<Facebook User Id>"; String status = "I am using the App42 API"; socialService.UpdateFacebookStatus(userName, status, this); void App42Callback.OnException(App42Exception exception) { Console.WriteLine("Exception Message"); } void App42Callback.OnSuccess(Object response) { Social social = (Social) response; Console.WriteLine("userName is" + social.GetUserName()); Console.WriteLine("status is" + social.GetStatus()); String jsonResponse = social.ToString(); } }String userName = "<Facebook User Id>"; String status = "I am using the App42 API"; Social social = socialService.updateFacebookStatus(userName, status); System.out.println("userName is " + social.getUserName()); System.out.println("fb Access Token is " + social.getStatus()); String jsonResponse = social.toString();var userName = "<Facebook User Id>", status = "I am using the App42 API", social ; socialService.updateFacebookStatus(userName, status,{ success: function(object) { var response = JSON.parse(object); social = response.app42.response.social; console.log("userName is " + social.userName) console.log("status is " + social.status) }, error: function(error) { } });String userName = "<Facebook User Id>"; String status = "I am using the App42 API"; Social social = socialService.updateFacebookStatus(userName, status); System.out.println("userName is " + social.getUserName()); System.out.println("status is " + social.getStatus()); String jsonResponse = social.toString();String userName = "<Facebook User Id>"; String status = "I am using the App42 API"; App42Log.SetDebug(true); //Print output in your editor console socialService.UpdateFacebookStatus(userName, status, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { Social social = (Social) response; App42Log.Console("userName is" + social.GetUserName()); App42Log.Console("status is" + social.GetStatus()); } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }String userName = "<Facebook User Id>"; String status = "I am using the App42 API"; Social social = socialService.UpdateFacebookStatus(userName, status); Console.WriteLine("userName is" + social.GetUserName()); Console.WriteLine("status is" + social.GetStatus()); String jsonResponse = social.ToString();$userName = "<Facebook User Id>"; $status = "I am using the App42 API"; $social = $socialService->updateFacebookStatus($userName, $status); Print_r("userName is" . $social->getUserName()); Print_r("status is" . $social->getStatus()); $jsonResponse = $social->toString();N/AN/AN/A
You can fetch Facebook friends of your linked app users as shown below in the snippet.
String userName = "<Facebook User Id>"; socialService.getFacebookFriendsFromLinkUser(userName, new App42CallBack() { public void onSuccess(Object response) { Social social = (Social)response; for(int i =0; i < social.getFriendList().size();i++) { System.out.println("Installed is : " + social.getFriendList().get(i).getInstalled()); System.out.println("Id is : " + social.getFriendList().get(i).getId()); System.out.println("Picture is :" + social.getFriendList().get(i).getPicture()); System.out.println("Name is : " + social.getFriendList().get(i).getName()); } } public void onException(Exception ex) { System.out.println("Exception Message"+ex.getMessage()); } });Coming Soonpublic class Callback : App42Callback { String userName = "<Facebook User Id>"; socialService.GetFacebookFriendsFromLinkUser(userName, this); void App42Callback.OnException(App42Exception exception) { Console.WriteLine("Exception Message"); } void App42Callback.OnSuccess(Object response) { Social social = (Social) response; Console.WriteLine("userName is" + social.GetUserName()); Console.WriteLine("friendName is" + social.GetFriendList()[0].GetName()); String jsonResponse = social.ToString(); } }String userName = "<Facebook User Id>"; Social social = socialService.getFacebookFriendsFromLinkUser(userName); System.out.println("userName is " + social.getUserName()); System.out.println("friendName is " + ((Social.Friends)social.getFriendList().elementAt(0)).getName()); String jsonResponse = social.toString();var userName = "<Facebook User Id>", social ; socialService.getFacebookFriendsFromLinkUser(userName,{ success: function(object) { var response = JSON.parse(object); social = response.app42.response.social; console.log("userName is " + social.userName) }, error: function(error) { } });String userName = "<Facebook User Id>"; Social social = socialService.getFacebookFriendsFromLinkUser(userName); System.out.println("userName is " + social.getUserName()); System.out.println("friendName is " + social.getFriendList().get(0).getName()); String jsonResponse = social.toString();String userName = "<Facebook User Id>"; App42Log.SetDebug(true); //Print output in your editor console socialService.GetFacebookFriendsFromLinkUser(userName, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { Social social = (Social) response; App42Log.Console("userName is" + social.GetUserName()); for(int i =0; i < social.GetFriendList().Count;i++) { App42Log.Console("Installed is : " + social.GetFriendList()[i].GetInstalled()); App42Log.Console("Id is : " + social.GetFriendList()[i].GetId()); App42Log.Console("Name is : " + social.GetFriendList()[i].GetName()); } } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }String userName = "<Facebook User Id>"; Social social = socialService.GetFacebookFriendsFromLinkUser(userName); Console.WriteLine("userName is" + social.GetUserName()); Console.WriteLine("friendName is" + social.GetFriendList()[0].GetName()); String jsonResponse = social.ToString();$userName = "<Facebook User Id>"; $social = $socialService->getFacebookFriendsFromLinkUser($userName); Print_r("userName is" . $social->getUserName()); Print_r("friendName is" . $social->getFriendList()[0]->getName()); $jsonResponse = $social->toString();N/AN/AN/A
You are free to use the Facebook SDK with your target platform directly without using App42 Social service method if you require. App42 Social APIs do not interfere with the native Facebook SDKs and can be used in isolation.
Go To Social API Usage Guide for more details
OR
Go To Integrating Gaming Backend for making social engaging games.