I am getting an error when trying to use Facebook Unity SDK:
Could not securely load assembly from https://integrated-plugin-canvas-rsrc.fbsbx.com/rsrc/unity/lib/sdk_4.0/CanvasFacebook.dll UnityEngine.Debug:LogError(Object) FbDebug:Error(String) c__Iterator3:MoveNext() (at Assets/Ultimate GUI Kit/Facebook/Scripts/FB.cs:337)
I am aware that usually you just add if unity 4.6 to the FB.cs
. However in the template I started with this class doesn't have this line. So how can i fix it? Here is definition of RemoteFacebookLoader
class from my FB.cs
file:
public abstract class RemoteFacebookLoader: MonoBehaviour {
public delegate void LoadedDllCallback(IFacebook fb);
private const string facebookNamespace = "Facebook.";
private const int maxRetryLoadCount = 3;
private static int retryLoadCount = 0;
public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback) {
#if UNITY_EDITOR || UNITY_WEBPLAYER
var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);
var www = new WWW(url);
FbDebug.Log("loading dll: " + url);
yield
return www;
if (www.error != null) {
FbDebug.Error(www.error);
if (retryLoadCount < maxRetryLoadCount) {
++retryLoadCount;
#else
var www = new WWW("");
yield
return www;#endif#
if UNITY_WEBPLAYER FBComponentFactory.AddComponent < CanvasFacebookLoader > ();#endif#
if UNITY_EDITOR || UNITY_WEBPLAYER
}
www.Dispose();
yield
break;
}
var assembly = Security.LoadAndVerifyAssembly(www.bytes, );
if (assembly == null) {
FbDebug.Error("Could not securely load assembly from " + url);
www.Dispose();
yield
break;
}
var facebookClass = assembly.GetType(facebookNamespace + className);
if (facebookClass == null) {
FbDebug.Error(className + " not found in assembly!");
www.Dispose();
yield
break;
}
// load the Facebook component into the gameobject
// using the "as" cast so it'll null if it fails to cast, instead of exception
var fb = typeof(FBComponentFactory)
.GetMethod("GetComponent")
.MakeGenericMethod(facebookClass)
.Invoke(null, new object[] {
IfNotExist.AddNew
}) as IFacebook;
if (fb == null) {
FbDebug.Error(className + " couldn't be created.");
www.Dispose();
yield
break;
}
callback(fb);
www.Dispose();
#endif
}
protected abstract string className {
get;
}
IEnumerator Start() {
var loader = LoadFacebookClass(className, OnDllLoaded);
while (loader.MoveNext()) {
yield
return loader.Current;
}
Destroy(this);
}
private void OnDllLoaded(IFacebook fb) {
FB.facebook = fb;
FB.OnDllLoaded();
}
}
Update
Looks like I was using old Facebook SDK (v4.0). So I updated FB.cs
file and now I am getting another errors. They say something about OGACTIONTYPE
and that unity can't load this type from IFacebook
assembly. Check out screenshot of unity console.
Actually it says:
Assets/Ultimate GUI Kit/Facebook/Scripts/FB.cs(212,13): error CS0246: The type or namespace name `OGActionType' could not be found. Are you missing a using directive or an assembly reference?
Here is definition of RemoteFacebookLoader
class from FB.cs
file that I just loaded:
public abstract class RemoteFacebookLoader : MonoBehaviour
{
public delegate void LoadedDllCallback(IFacebook fb);
private const string facebookNamespace = "Facebook.";
private const int maxRetryLoadCount = 3;
private static int retryLoadCount = 0;
public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback)
{
var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);
var www = new WWW(url);
FbDebug.Log("loading dll: " + url);
yield return www;
if (www.error != null)
{
FbDebug.Error(www.error);
if (retryLoadCount < maxRetryLoadCount)
{
++retryLoadCount;
#if UNITY_WEBPLAYER
FBComponentFactory.AddComponent<CanvasFacebookLoader>();
#endif
}
www.Dispose();
yield break;
}
#if !UNITY_WINRT
#if UNITY_4_5 || UNITY_4_6 || UNITY_5_0
var authTokenWww = new WWW(IntegratedPluginCanvasLocation.KeyUrl);
yield return authTokenWww;
if (authTokenWww.error != null)
{
FbDebug.Error("Cannot load from " + IntegratedPluginCanvasLocation.KeyUrl + ": " + authTokenWww.error);
authTokenWww.Dispose();
yield break;
}
var assembly = Security.LoadAndVerifyAssembly(www.bytes, authTokenWww.text);
#else
var assembly = Security.LoadAndVerifyAssembly(www.bytes);
#endif
if (assembly == null)
{
FbDebug.Error("Could not securely load assembly from " + url);
www.Dispose();
yield break;
}
var facebookClass = assembly.GetType(facebookNamespace + className);
if (facebookClass == null)
{
FbDebug.Error(className + " not found in assembly!");
www.Dispose();
yield break;
}
// load the Facebook component into the gameobject
// using the "as" cast so it'll null if it fails to cast, instead of exception
var fb = typeof(FBComponentFactory)
.GetMethod("GetComponent")
.MakeGenericMethod(facebookClass)
.Invoke(null, new object[] { IfNotExist.AddNew }) as IFacebook;
if (fb == null)
{
FbDebug.Error(className + " couldn't be created.");
www.Dispose();
yield break;
}
callback(fb);
#endif
www.Dispose();
}
protected abstract string className { get; }
IEnumerator Start()
{
var loader = LoadFacebookClass(className, OnDllLoaded);
while (loader.MoveNext())
{
yield return loader.Current;
}
Destroy(this);
}
private void OnDllLoaded(IFacebook fb)
{
FB.facebook = fb;
FB.OnDllLoaded();
}
}