Background:
I am trying to integrate facebook for a unity-android project and I can’t seem to make it working, I have looked on the fb page and allot of other place but can’t seem to find a what I am doing wrong.
Problem:
When trying FB.Login i get the reference exception: Facebook object is not loaded. Did you call FB.init?
Code for InitializeFB.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Facebook.MiniJSON;
using System;
public class ConncetToFaceBook : MonoBehaviour {
// Connect to facebook
void Awake () {
// Required
DontDestroyOnLoad(gameObject);
// Initialize FB SDK
enabled = false;
FB.Init(onInitComplete, OnHideUnity);
//Display id
Debug.Log (FB.UserId);
//Login to facebook
FB.Login("email,publish_actions", LoginCallback);
}
/* Helper Methods */
private void onInitComplete ()
{
enabled = true; // "enabled" is a property inherited from MonoBehaviour
if (FB.IsLoggedIn)
{
//Some Code
}
}
private void OnHideUnity(bool isGameShown)
{
//some code
}
void LoginCallback(FBResult result)
{
if (FB.IsLoggedIn)
{
OnLoggedIn();
}
}
void OnLoggedIn()
{
Debug.Log("Logged in. ID: " + FB.UserId);
}
}
Code for FB.init
public static void Init(
InitDelegate onInitComplete,
string appId = "{My app ID}", //I did put my own here. Plus I use " instead of ' because ' give me a error.
bool cookie = true,
bool logging = true,
bool status = true,
bool xfbml = true,
bool frictionlessRequests = true,
HideUnityDelegate onHideUnity = null,
string authResponse = null)