/// <summary> /// FB.Init as per Unity SDK /// </summary> /// <remarks> /// https://developers.facebook.com/docs/unity/reference/current/FB.Init /// </remarks> public static void Init(InitDelegate onInitComplete, string appId, HideUnityDelegate onHideUnity) { #if WINDOWS_PHONE_APP Dispatcher.InvokeOnUIThread(() => { _onHideUnity = onHideUnity; _fbSessionClient = Session.ActiveSession; Session.AppId = appId; Task.Run(async () => { // check and extend token if required await Session.CheckAndExtendTokenIfNeeded(); if (IsLoggedIn) { UserId = Settings.GetString(FBID_KEY); UserName = Settings.GetString(FBNAME_KEY); } if (onInitComplete != null) { Dispatcher.InvokeOnAppThread(() => { onInitComplete(); }); } }); if (onHideUnity != null) throw new NotSupportedException("onHideUnity is not currently supported at this time."); }); #else throw new PlatformNotSupportedException(""); #endif }
public virtual void Init( HideUnityDelegate hideUnityDelegate, InitDelegate onInitComplete) { this.onHideUnityDelegate = hideUnityDelegate; this.onInitCompleteDelegate = onInitComplete; }
void Awake() { initDelegate = OnFacebookInitialized; hideUnityDelegate = OnHideUnity; onRoundInformationReceivedDelegate = OnRoundInformationReceived; FB.Init (OnFacebookInitialized, OnHideUnity); }
public abstract void Init( InitDelegate onInitComplete, string appId, bool cookie = false, bool logging = true, bool status = true, bool xfbml = false, string channelUrl = "", string authResponse = null, bool frictionlessRequests = false, HideUnityDelegate hideUnityDelegate = null);
/** * This is the preferred way to call FB.Init(). It will take the facebook app id specified in your * "Facebook" => "Edit Settings" menu when it is called. * * onInitComplete - Delegate is called when FB.Init() finished initializing everything. * By passing in a delegate you can find out when you can safely call the other methods. */ public static void Init(InitDelegate onInitComplete, HideUnityDelegate onHideUnity = null, string authResponse = null) { Init( onInitComplete, FBSettings.AppId, FBSettings.Cookie, FBSettings.Logging, FBSettings.Status, FBSettings.Xfbml, FBSettings.FrictionlessRequests, onHideUnity, authResponse); }
public virtual void Init( string appId, bool cookie, bool logging, bool status, bool xfbml, string channelUrl, string authResponse, bool frictionlessRequests, HideUnityDelegate hideUnityDelegate, InitDelegate onInitComplete) { this.onHideUnityDelegate = hideUnityDelegate; this.onInitCompleteDelegate = onInitComplete; }
public override void Init( InitDelegate onInitComplete, string appId, bool cookie, bool logging, bool status, bool xfbml, string channelUrl, string authResponse, bool frictionlessRequests, HideUnityDelegate hideUnityDelegate) { if (onInitComplete != null) { onInitComplete(); } var editorFB = ComponentFactory.GetComponent<EditorFacebookGameObject>(); editorFB.OnInitComplete(""); }
/** * If you need a more programmatic way to set the facebook app id and other setting call this function. * Useful for a build pipeline that requires no human input. */ public static void Init( InitDelegate onInitComplete, string appId, bool cookie = true, bool logging = true, bool status = true, bool xfbml = false, bool frictionlessRequests = true, HideUnityDelegate onHideUnity = null, string authResponse = null) { FB.appId = appId; FB.cookie = cookie; FB.logging = logging; FB.status = status; FB.xfbml = xfbml; FB.frictionlessRequests = frictionlessRequests; FB.authResponse = authResponse; FB.OnInitComplete = onInitComplete; FB.OnHideUnity = onHideUnity; if (!isInitCalled) { var versionInfo = FBBuildVersionAttribute.GetVersionAttributeOfType(typeof (IFacebook)); if (versionInfo == null) { FbDebug.Warn("Cannot find Facebook SDK Version"); } else { FbDebug.Info(String.Format("Using SDK {0}, Build {1}", versionInfo.SdkVersion, versionInfo.BuildVersion)); } #if UNITY_EDITOR FBComponentFactory.GetComponent<EditorFacebookLoader>(); #elif UNITY_WEBPLAYER FBComponentFactory.GetComponent<CanvasFacebookLoader>(); #elif UNITY_IOS FBComponentFactory.GetComponent<IOSFacebookLoader>(); #elif UNITY_ANDROID FBComponentFactory.GetComponent<AndroidFacebookLoader>(); #else throw new NotImplementedException("Facebook API does not yet support this platform"); #endif isInitCalled = true; return; } FbDebug.Warn("FB.Init() has already been called. You only need to call this once and only once."); // Init again if possible just in case something bad actually happened. if (FacebookImpl != null) { OnDllLoaded(); } }
/// <summary> /// If you need a more programmatic way to set the facebook app id and other setting call this function. /// Useful for a build pipeline that requires no human input. /// </summary> /// <param name="appId">App identifier.</param> /// <param name="clientToken">App client token.</param> /// <param name="cookie">If set to <c>true</c> cookie.</param> /// <param name="logging">If set to <c>true</c> logging.</param> /// <param name="status">If set to <c>true</c> status.</param> /// <param name="xfbml">If set to <c>true</c> xfbml.</param> /// <param name="frictionlessRequests">If set to <c>true</c> frictionless requests.</param> /// <param name="authResponse">Auth response.</param> /// <param name="javascriptSDKLocale"> /// The locale of the js sdk used see /// https://developers.facebook.com/docs/internationalization#plugins. /// </param> /// <param name="onHideUnity"> /// A delegate to invoke when unity is hidden. /// </param> /// <param name="onInitComplete"> /// Delegate is called when FB.Init() finished initializing everything. By passing in a delegate you can find /// out when you can safely call the other methods. /// </param> public static void Init( string appId, string clientToken = null, bool cookie = true, bool logging = true, bool status = true, bool xfbml = false, bool frictionlessRequests = true, string authResponse = null, string javascriptSDKLocale = FB.DefaultJSSDKLocale, HideUnityDelegate onHideUnity = null, InitDelegate onInitComplete = null) { if (string.IsNullOrEmpty(appId)) { throw new ArgumentException("appId cannot be null or empty!"); } FB.AppId = appId; FB.ClientToken = clientToken; if (!isInitCalled) { isInitCalled = true; if (Constants.IsEditor) { FB.OnDLLLoadedDelegate = delegate { ((EditorFacebook)FB.facebook).Init(onInitComplete); }; ComponentFactory.GetComponent <EditorFacebookLoader>(); ComponentFactory.GetComponent <CodelessCrawler>(); ComponentFactory.GetComponent <CodelessUIInteractEvent>(); } else { switch (Constants.CurrentPlatform) { case FacebookUnityPlatform.WebGL: FB.OnDLLLoadedDelegate = delegate { ((CanvasFacebook)FB.facebook).Init( appId, cookie, logging, status, xfbml, FacebookSettings.ChannelUrl, authResponse, frictionlessRequests, javascriptSDKLocale, Constants.DebugMode, onHideUnity, onInitComplete); }; ComponentFactory.GetComponent <CanvasFacebookLoader>(); break; case FacebookUnityPlatform.IOS: FB.OnDLLLoadedDelegate = delegate { ((IOSFacebook)FB.facebook).Init( appId, frictionlessRequests, FacebookSettings.IosURLSuffix, onHideUnity, onInitComplete); }; ComponentFactory.GetComponent <IOSFacebookLoader>(); ComponentFactory.GetComponent <CodelessCrawler>(); ComponentFactory.GetComponent <CodelessUIInteractEvent>(); break; case FacebookUnityPlatform.Android: FB.OnDLLLoadedDelegate = delegate { ((AndroidFacebook)FB.facebook).Init( appId, onHideUnity, onInitComplete); }; ComponentFactory.GetComponent <AndroidFacebookLoader>(); ComponentFactory.GetComponent <CodelessCrawler>(); ComponentFactory.GetComponent <CodelessUIInteractEvent>(); break; case FacebookUnityPlatform.Gameroom: FB.OnDLLLoadedDelegate = delegate { ((GameroomFacebook)FB.facebook).Init(appId, onHideUnity, onInitComplete); }; ComponentFactory.GetComponent <GameroomFacebookLoader>(); break; default: throw new NotSupportedException("The facebook sdk does not support this platform"); } } } else { FacebookLogger.Warn("FB.Init() has already been called. You only need to call this once and only once."); } }
public override void Init( InitDelegate onInitComplete, string appId, bool cookie = false, bool logging = true, bool status = true, bool xfbml = false, string channelUrl = "", string authResponse = null, bool frictionlessRequests = false, HideUnityDelegate hideUnityDelegate = null) { if (string.IsNullOrEmpty(appId)) { throw new ArgumentException("appId cannot be null or empty!"); } var parameters = new Dictionary<string, object>(); parameters.Add("appId", appId); if (cookie != false) { parameters.Add("cookie", true); } if (logging != true) { parameters.Add("logging", false); } if (status != true) { parameters.Add("status", false); } if (xfbml != false) { parameters.Add("xfbml", true); } if (!string.IsNullOrEmpty(channelUrl)) { parameters.Add("channelUrl", channelUrl); } if (!string.IsNullOrEmpty(authResponse)) { parameters.Add("authResponse", authResponse); } if (frictionlessRequests != false) { parameters.Add("frictionlessRequests", true); } var paramJson = MiniJSON.Json.Serialize(parameters); this.onInitComplete = onInitComplete; this.CallFB("Init", paramJson.ToString()); }
/// <summary> /// This is the preferred way to call FB.Init(). It will take the facebook app id specified in your "Facebook" /// => "Edit Settings" menu when it is called. /// </summary> /// <param name="onInitComplete"> /// Delegate is called when FB.Init() finished initializing everything. By passing in a delegate you can find /// out when you can safely call the other methods. /// </param> /// <param name="onHideUnity">A delegate to invoke when unity is hidden.</param> /// <param name="authResponse">Auth response.</param> public static void Init(InitDelegate onInitComplete = null, HideUnityDelegate onHideUnity = null, string authResponse = null) { Init( FacebookSettings.AppId, FacebookSettings.ClientToken, FacebookSettings.Cookie, FacebookSettings.Logging, FacebookSettings.Status, FacebookSettings.Xfbml, FacebookSettings.FrictionlessRequests, authResponse, FB.DefaultJSSDKLocale, onHideUnity, onInitComplete); }
public override void Init( HideUnityDelegate hideUnityDelegate, InitDelegate onInitComplete) { // Warn that editor behavior will not match supported platforms FacebookLogger.Warn(WarningMessage); base.Init( hideUnityDelegate, onInitComplete); this.editorWrapper.Init(); }
public void Init( string appId, HideUnityDelegate hideUnityDelegate, InitDelegate onInitComplete) { base.Init(onInitComplete); this.appId = appId; string accessTokenInfo; Utilities.CommandLineArguments.TryGetValue("/access_token", out accessTokenInfo); if (accessTokenInfo != null) { accessTokenInfo = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(accessTokenInfo)); this.OnInitComplete(new ResultContainer(accessTokenInfo)); } else { this.OnInitComplete(new ResultContainer(string.Empty)); } }
public static void Init( InitDelegate onInitComplete, string appId, HideUnityDelegate onHideUnity, string redirectUrl = null) { if (_client != null) { if (onInitComplete != null) onInitComplete(); return; } if (_web == null) throw new MissingScaffoldingException(); if (string.IsNullOrEmpty(appId)) throw new ArgumentException("Invalid Facebook App ID"); if (!string.IsNullOrEmpty(redirectUrl)) _redirectUrl = redirectUrl; _client = new FacebookClient(); _client.GetCompleted += HandleGetCompleted; AppId = _client.AppId = appId; _onHideUnity = onHideUnity; //// TODO: Replace this code with appropriate Facebook.Client calls //if (Settings.HasKey(TOKEN_KEY)) //{ // AccessToken = EncryptionProvider.Decrypt(Settings.GetString(TOKEN_KEY), AppId); // if (Settings.HasKey(EXPIRY_DATE)) // { // string expDate = EncryptionProvider.Decrypt(Settings.GetString(EXPIRY_DATE), AppId); // Expires = DateTime.Parse(expDate, CultureInfo.InvariantCulture); // } // else // { // long expDate = Settings.GetLong(EXPIRY_DATE_BIN); // Expires = DateTime.FromBinary(expDate); // } // _client.AccessToken = AccessToken; // UserId = Settings.GetString(FBID_KEY); // UserName = Settings.GetString(FBNAME_KEY); // // verifies if the token has expired: // if (DateTime.Compare(DateTime.UtcNow, Expires) > 0) // InvalidateData(); // //var task = TestAccessToken(); // //task.Wait(); //} if (onInitComplete != null) onInitComplete(); }
/// <summary> /// FB.Init as per Unity SDK /// </summary> /// <remarks> /// https://developers.facebook.com/docs/unity/reference/current/FB.Init /// </remarks> public static void Init(InitDelegate onInitComplete, string appId, HideUnityDelegate onHideUnity) { Utils.RunOnWindowsUIThread(() => { _onHideUnity = onHideUnity; _fbSessionClient = Session.ActiveSession; Session.AppId = appId; Task.Run(() => { // TODO: Make check and extend token available to Windows // await Session.CheckAndExtendTokenIfNeeded(); if (onInitComplete != null) Utils.RunOnUnityAppThread(() => { onInitComplete(); }); }); if (onHideUnity != null) throw new NotSupportedException("onHideUnity is not currently supported at this time."); }); }
public abstract void Init( InitDelegate onInitComplete, string appId, bool cookie, bool logging, bool status, bool xfbml, string channelUrl, string authResponse, bool frictionlessRequests, HideUnityDelegate hideUnityDelegate);
/** * If you need a more programmatic way to set the facebook app id and other setting call this function. * Useful for a build pipeline that requires no human input. */ public static void Init( InitDelegate onInitComplete, string appId, bool cookie = true, bool logging = true, bool status = true, bool xfbml = false, bool frictionlessRequests = true, HideUnityDelegate onHideUnity = null, string authResponse = null) { FB.appId = appId; FB.cookie = cookie; FB.logging = logging; FB.status = status; FB.xfbml = xfbml; FB.frictionlessRequests = frictionlessRequests; FB.authResponse = authResponse; FB.OnInitComplete = onInitComplete; FB.OnHideUnity = onHideUnity; if (!isInitCalled) { FB.LogVersion(); #if UNITY_EDITOR FBComponentFactory.GetComponent<EditorFacebookLoader>(); #elif UNITY_WEBPLAYER || UNITY_WEBGL FBComponentFactory.GetComponent<CanvasFacebookLoader>(); #elif UNITY_IOS FBComponentFactory.GetComponent<IOSFacebookLoader>(); #elif UNITY_ANDROID FBComponentFactory.GetComponent<AndroidFacebookLoader>(); #else throw new NotImplementedException("Facebook API does not yet support this platform"); #endif isInitCalled = true; return; } FBDebug.Warn("FB.Init() has already been called. You only need to call this once and only once."); // Init again if possible just in case something bad actually happened. if (FacebookImpl != null) { OnDllLoaded(); } }
public static void Init( InitDelegate onInitComplete, string appId, HideUnityDelegate onHideUnity, string redirectUrl = null) { onInitComplete(); onHideUnity(false); }
/// <summary> /// If you need a more programmatic way to set the facebook app id and other setting call this function. /// Useful for a build pipeline that requires no human input. /// </summary> /// <param name="appId">App identifier.</param> /// <param name="clientToken">App client token.</param> /// <param name="cookie">If set to <c>true</c> cookie.</param> /// <param name="logging">If set to <c>true</c> logging.</param> /// <param name="status">If set to <c>true</c> status.</param> /// <param name="xfbml">If set to <c>true</c> xfbml.</param> /// <param name="frictionlessRequests">If set to <c>true</c> frictionless requests.</param> /// <param name="authResponse">Auth response.</param> /// <param name="javascriptSDKLocale"> /// The locale of the js sdk used see /// https://developers.facebook.com/docs/internationalization#plugins. /// </param> /// <param name="onHideUnity"> /// A delegate to invoke when unity is hidden. /// </param> /// <param name="onInitComplete"> /// Delegate is called when FB.Init() finished initializing everything. By passing in a delegate you can find /// out when you can safely call the other methods. /// </param> public static void Init( string appId, string clientToken = null, bool cookie = true, bool logging = true, bool status = true, bool xfbml = false, bool frictionlessRequests = true, string authResponse = null, string javascriptSDKLocale = FB.DefaultJSSDKLocale, HideUnityDelegate onHideUnity = null, InitDelegate onInitComplete = null) { if (string.IsNullOrEmpty(appId)) { throw new ArgumentException("appId cannot be null or empty!"); } FB.AppId = appId; FB.ClientToken = clientToken; if (!isInitCalled) { isInitCalled = true; if (Constants.IsEditor) { FB.OnDLLLoadedDelegate = delegate { ((EditorFacebook)FB.facebook).Init(onInitComplete); }; ComponentFactory.GetComponent<EditorFacebookLoader>(); } else { switch (Constants.CurrentPlatform) { case FacebookUnityPlatform.WebGL: FB.OnDLLLoadedDelegate = delegate { ((CanvasFacebook)FB.facebook).Init( appId, cookie, logging, status, xfbml, FacebookSettings.ChannelUrl, authResponse, frictionlessRequests, javascriptSDKLocale, Constants.DebugMode, onHideUnity, onInitComplete); }; ComponentFactory.GetComponent<CanvasFacebookLoader>(); break; case FacebookUnityPlatform.IOS: FB.OnDLLLoadedDelegate = delegate { ((IOSFacebook)FB.facebook).Init( appId, frictionlessRequests, FacebookSettings.IosURLSuffix, onHideUnity, onInitComplete); }; ComponentFactory.GetComponent<IOSFacebookLoader>(); break; case FacebookUnityPlatform.Android: FB.OnDLLLoadedDelegate = delegate { ((AndroidFacebook)FB.facebook).Init( appId, onHideUnity, onInitComplete); }; ComponentFactory.GetComponent<AndroidFacebookLoader>(); break; case FacebookUnityPlatform.Arcade: FB.OnDLLLoadedDelegate = delegate { ((ArcadeFacebook)FB.facebook).Init(appId, onHideUnity, onInitComplete); }; ComponentFactory.GetComponent<ArcadeFacebookLoader>(); break; default: throw new NotSupportedException("The facebook sdk does not support this platform"); } } } else { FacebookLogger.Warn("FB.Init() has already been called. You only need to call this once and only once."); } }
public static void Init( InitDelegate onInitComplete, string appId, HideUnityDelegate onHideUnity, string redirectUrl = null) { #if NETFX_CORE if (_client != null) { if (onInitComplete != null) onInitComplete(); return; } if (_web == null) throw new MissingPlatformException(); if (string.IsNullOrEmpty(appId)) throw new ArgumentException("Invalid Facebook App ID"); if (!string.IsNullOrEmpty(redirectUrl)) _redirectUrl = redirectUrl; _client = new FacebookClient(); _client.GetCompleted += HandleGetCompleted; AppId = _client.AppId = appId; _onHideUnity = onHideUnity; if (Settings.HasKey(TOKEN_KEY)) { AccessToken = EncryptionProvider.Decrypt(Settings.GetString(TOKEN_KEY), AppId); if (Settings.HasKey(EXPIRY_DATE)) { string expDate = EncryptionProvider.Decrypt(Settings.GetString(EXPIRY_DATE), AppId); Expires = DateTime.Parse(expDate, CultureInfo.InvariantCulture); } else { long expDate = Settings.GetLong(EXPIRY_DATE_BIN); Expires = DateTime.FromBinary(expDate); } _client.AccessToken = AccessToken; UserId = Settings.GetString(FBID_KEY); UserName = Settings.GetString(FBNAME_KEY); // verifies if the token has expired: if (DateTime.Compare(DateTime.UtcNow, Expires) > 0) InvalidateData(); //var task = TestAccessToken(); //task.Wait(); } if (onInitComplete != null) onInitComplete(); #else throw new PlatformNotSupportedException(""); #endif }
public override void Init( InitDelegate onInitComplete, string appId, bool cookie = false, bool logging = true, bool status = true, bool xfbml = false, string channelUrl = "", string authResponse = null, bool frictionlessRequests = false, HideUnityDelegate hideUnityDelegate = null) { if (string.IsNullOrEmpty(appId)) { throw new ArgumentException("appId cannot be null or empty!"); } if (integrationMethodJs == null) { #if !UNITY_EDITOR throw new Exception("Cannot initialize facebook javascript"); #endif } this.onInitComplete = onInitComplete; OnHideUnity = hideUnityDelegate; var parameters = new Dictionary<string, object>(); this.appId = appId; parameters.Add("appId", appId); if (cookie != false) { parameters.Add("cookie", true); } if (logging != true) { parameters.Add("logging", false); } if (status != true) { parameters.Add("status", false); } if (xfbml != false) { parameters.Add("xfbml", true); } if (!string.IsNullOrEmpty(channelUrl)) { parameters.Add("channelUrl", channelUrl); } if (!string.IsNullOrEmpty(authResponse)) { parameters.Add("authResponse", authResponse); } if (frictionlessRequests != false) { parameters.Add("frictionlessRequests", true); } // Post-F8 SDK mandates specifying a version parameters.Add("version", "v2.2"); var paramJson = MiniJSON.Json.Serialize(parameters); Application.ExternalEval(integrationMethodJs); bool isPlayer = true; #if UNITY_WEBGL isPlayer = false; #endif // use 1/0 for booleans, otherwise you'll get strings "True"/"False" Application.ExternalCall("FBUnity.init", isPlayer ? 1 : 0, FacebookConnectURL, sdkLocale, sdkDebug ? 1 : 0, paramJson, status ? 1 : 0); }
public virtual void Init(HideUnityDelegate hideUnityDelegate, InitDelegate onInitComplete) { this.onHideUnityDelegate = hideUnityDelegate; this.onInitCompleteDelegate = onInitComplete; }