Integrate FaceBook_SDK

Downlaod the Facebook SDK for unity I have 6.0 you can download by this link or goto google and search for its latest version.

https://www.dropbox.com/s/1o50rv3efy6mx49/FacebookSDK-141217.unitypackage?dl=0

Import that pakage to unity

Create an Empty object and name what ever you watnt for me I renamed it by FBHolder then make a script for my case I create FBHolder.cs and open it in your favorite editor.

First thing first what I mean that

I mean you have to initialize FB first so

In FBHolder.cs write hence Awake() becomes

void Awake () {

FB.Init(SetInt,OnHideUnity);

}

Now write SetInt and OnHideUnity methods.

private void SetInt()

{

//its check wheather the FB init is done or not

Debug.Log("FB Init Done");

//Its check either FB logged in or not.this is the advance form of if-else statementif (FB.IsLoggedIn)

{

Debug.Log("FB LOGGED IN SUCCESS");

}

else

{

FB_Login();

}

}

private void OnHideUnity(bool isGameShown)

{

//isGameShown mean the windows for FB login is shown or not in Gameview

//!isGameShown means that is window shown in screen

Time.timeScale = !isGameShown ? 0 : 1;

}

Now before checking it goto FACEBOOK->EditSettings in unity menu bar

In APPID write yours app id from just go to link below and create an app so you get APPID

https://developers.facebook.com/apps/

Save the setting and run the app

You have the massage logged in successful.

One thing to remember that FB.______ (any thing) first want to FB.Init first mean (First need to initialize FB first)

Then again goto FBHolder.cs and write to basic Login Functionality

void FB_Login()

{

FB.Login("user_about_me, user_birthday",AutoCallBack);

}

private void AutoCallBack(FBResult result)

{

Debug.Log(FB.IsLoggedIn ? "FB Login Worked" : "FB Login Failed");

}

And call FB_Login().

Now goto unity and Run it . after it initialize it want the token so click on get token and paste it in the field and press login you should see FB LOGED IN WORKED. And that’s it.

Comments