General Features

This document provides the API details for the majority of common Facebook SDK methods. The architecture follows, as much as possible within the constraints of the supported platforms and of Mono. Most data exchanged over the network is marshaled as strings containing JSON, and a utility class, Json, which is provided to help manage that data within Unity.


Sets the state of the Facebook SDK, and initializes all platform-specific data structures and behaviors. This function can be only called once during the lifetime of the object; later calls lead to undefined behavior. Init() relies on properties that are set in the editor using the Facebook | Edit settings... menu option.

Note: After initialization is completed, a user can be authenticated in case he has passed the Facebook authentication with your app in the previous game sessions. So, you should keep this in mind and check if a user is authenticated after initialization is completed.


SPFacebook.instance.OnInitCompleteAction += OnInit;
SPFacebook.instance.OnFocusChangedAction += OnFocusChanged;

private void OnInit() {
    Debug.Log("FB init finished");
	if(SPFacebook.instance.IsLoggedIn) {
		//User alreayd authenticated, update your UI accordingly
private void OnFocusChanged(bool focus) {
	if (!focus)  {                                                                                  
		// pause the game - we will need to hide                                             
		Time.timeScale = 0;                                                                  
	} else  {                                                                                       
		// start the game back up - we're getting focus again                                
		Time.timeScale = 1;                                                                  



Prompts the user to authorize your application using the Login Dialog appropriate to the platform. If the user has been already logged in and has authorized your application, check whether all permissions in the scope parameter have been granted, and if not, prompt the user for any that are newly requested. Usually, you'll call it once to ask the user for authentication, then again to request additional permissions as required.

Note: OnAuthCompleteAction contains  FBResult object. But the best way to check if the user logged in successfully is to check SPFacebook.instance.IsLoggedIn flag.


SPFacebook.OnAuthCompleteAction += OnAuth;

private void OnAuth(FB_Result result) {
	if(SPFacebook.instance.IsLoggedIn) {
		IsAuntificated = true;
		SA_StatusBar.text = "user Login -> true";
	} else {
		Debug.Log("Failed to log in");



Logout is much simplier, just call this method:



Note: We can also get current FB API state using the following properties:

public bool IsInited {get;}
public bool IsLoggedIn {get;}
public string UserId {get;}
public string AccessToken {get;}
public string AppId {get;}
public string userInfo {get;}
public string userInfo {get;}


Retrieving user data

The following code snippet will show a user the data retrieving example:

SPFacebook.instance.OnUserDataRequestCompleteAction += OnUserDataLoaded;

private void OnUserDataLoaded(FB_Result result) {
	SPFacebook.instance.OnUserDataRequestCompleteAction -= OnUserDataLoaded;

	if (result.Error == null)  { 
		SA_StatusBar.text = "User data loaded";
		IsUserInfoLoaded = true;

		//user data avaliable, we can get info using
		//SPFacebook.instance.userInfo getter
		//and we can also use userInfo methods, for exmple download user avatar image

	} else {
		SA_StatusBar.text ="Opps, user data load failed, something was wrong";
		Debug.Log("Opps, user data load failed, something was wrong");


The user data is represented as FB_UserInfo class.

public string Id {get;}
public string Name {get;}
public string FirstName {get;}
public string LastName {get;}
public string UserName{get;}
public string ProfileUrl {get;}
public string Email {get;}
public string Locale {get;}
public string Location {get;}
public FB_Gender Gender {get;}
public string RawJSON {get;}
public DateTime Birthday {get;}

public string GetProfileUrl(FacebookProfileImageSize size)
public Texture2D  GetProfileImage(FacebookProfileImageSize size)
public void LoadProfileImage(FacebookProfileImageSize size)

public enum FacebookProfileImageSize {



The code snippet below shows an example of retrieving user friends list.

SPFacebook.OnFriendsDataRequestCompleteAction += OnFriendsDataLoaded;

int limit = 5;

private void OnFriendsDataLoaded(FB_Result res) {
	SPFacebook.OnFriendsDataRequestCompleteAction -= OnFriendsDataLoaded;

	if(res.Error == null) {
		//friednds data avaliable, we can get it using
		//SPFacebook.instance.friendsList getter
		//and we can also use FacebookUserInfo methods, for exmple download user avatar image
		foreach(FB_UserInfo friend in SPFacebook.instance.friendsList) {
		IsFrindsInfoLoaded = true;
	} else {
		Debug.Log("Opps, friends data load failed, something was wrong");


After friends data is loaded, we can use the following methods of SPFacebook class to get it.

public FacebookUserInfo GetFriendById(string id)
public List<FB_UserInfo> friendsList {get;}



To post the feed from the user, you can use SPFacebook.instance.Post(.....) method which prompts a user to post a feed story. It can be posted in either his/her own timeline (if toId is blank, or set to the user's own Facebook user ID), or in that of one friend (if toID is set to the user ID of that friend). The metod is similar to FB.Feed method of unity Facebook SDK.

The SPFacebook.instance.PostWithAuthCheck(....) will do the same but it will run auth request if the user isn't authed when the PostWithAuthCheck is called. If a user is authored, it will work the same as  Post  method.

Code snippet:

private void PostWithAuthCheck() {
		SPFacebook.instance.FeedShare (
			link: "",
			linkName: "The Larch",
			linkCaption: "I thought up a witty tagline about larches",
			linkDescription: "There are a lot of larch trees around here, aren't there?",
			picture: ""


As you noticed, we can provide an image only as URL.  If you wnat to post Texture2D to the user wall, there are 2 options for this.

1) With me/photos Graph API. 

Code snippet:

SPFacebook.instance.PostImage("My app ScreehShot", tex);

The posting will be made in the background, so if you want to ask user permission for this,  you need to implement posting dialog by yourself.

Note: A user access token with user_photos permission is required.


2) With Native system API

SPShareUtility.FacebookShare("This is my text to share", ImageToShare);

This will create a native device FB post dialog. But do not forget to read Coding Guidelines and Platform Behavior differences before using native system API.


To find out posting result, we can subscribe to the OnPostingCompleteAction action.

SPFacebook.OnPostingCompleteAction += OnPost

private void OnPost(FB_PostResult res) {
	if(res.IsSucceeded) {
		Debug.Log("Posting complete");
		Debug.Log("Posy id: " + res.PostId);
		SA_StatusBar.text = "Posting complete";
	} else {
		SA_StatusBar.text = "Oops, post failed, something was wrong";
		Debug.Log("Oops, post failed, something was wrong");


if the result.Error == null it means that no issue occurred during posting flow. And even if the user cancels the post, we will not get the error. If you want to be sure that the user has posted a feed on his wall, you need to parse the result.Text JSON data and check if it contains the post id.


App Request

Prompts the user to send app requests, short messages between users. Please see the facebook official documentation for details.

Code snippet:

SPFacebook.instance.AppRequest("Come play this great game!");

Warning: The recipient will be able to get the notification only if you also have a canvas version of your app, which means that your app will have canvas URL since this is the URL where the notification links to. You just need to go to the Facebook developer and select your app and go into the setting of your app and click "Add Platform" and select "App On Facebook" and then add canvas URL in it. Now try to send the invitation and it will show the notification.

Note for IOS:

To ensure this works correctly, you need to supply an iPhone and/or iPad Store ID, and you need to ensure that both Single Sign On and Deep Linking are enabled for iOS under App Settings for your app.

Full API use example can be found under the Facebook example scene.