How do I use the Facebook SDk to login?

Yes, I know this is really a Facebook question but I can’t find any place on the facebook dev site to ask questions specifically about their Unity SDK.

Basically I’m using Javascript and as soon as I try to do the simplest piece of code:


I get a Unknown Identifier :‘FB’ error.

How do I fix/access the class?


you can use this and more api after this line…

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Facebook.MiniJSON;

public class FacebookManager : MonoBehaviour

	static FacebookManager instance = null;

	public string FullName;
	public string Gender;

	public static FacebookManager Instance ()
		return instance;

	void Awake ()
		if (instance == null)
			instance = this;
		FB.Init (onInitCallback, onHideUnityCallback);		
		DontDestroyOnLoad (gameObject);

	public void callInit ()
		FB.Init (onInitCallback, onHideUnityCallback);		

	public void callLogin (string permissions)
		FB.Login (permissions, onLoginCallback);

	public void callLogout ()
		FB.Logout ();

make it right answer if you find it usefull :slight_smile: thanks

Check that you’ve included the FB into the javascript youre calling that function
(I’m not sure that the FB SDK is available for javascript thought, but the classes calls should be the same as the reference)

In the docs from the facebook page there’s plenty of examples.

If you can’t manage to make it work on javascript write a wrapper or change to C#.
P.S: Make sure your settings from the Facebook->Edit Settings menu are set too.

For your info,

Becoz Facebook Unity SDK is written in C# and it is impossible to call those C# functions from javascript.

so convert your code in C# and try . it will be working and you feel it as easy…

hope this may help you.

The Facebook SDK only works in C#. It took me a while to figure that out too. If you need help translating it to C#, you can use this for help. Its a good start, but you will still have to run through it and fix a lot by hand. Convert unity javascript (unityscript) to C#