internal static void clearFacebookSession(Action <Boolean, Exception> callback) { if (facebook != null && facebook.isSessionValid()) { facebook.setAccessToken(null); } FacebookSession.clear(); clearFacebookCookies(callback); }
/// <summary> /// Logs a user into the registered application with Facebook account with Facebook permissions. /// </summary> /// <param name="permissionArray">Permission array</param> /// <param name="callback">Method to be called when login operation finishes</param> public static void login(String[] permissionArray, Action <NetmeraUser, Exception> callback) { String securityToken = NetmeraClient.getSecurityToken(); if (securityToken != null && securityToken.Trim() != "") { Popup popup = new Popup(); LoginUserControl control = new LoginUserControl(); control.btnCancel.Click += new RoutedEventHandler((s, e) => { NetmeraUser user = null; user = NetmeraUser.getCurrentUser(); if (callback != null) { callback(user, null); } }); try { NetmeraUser.clearSocialSessions((logout, ex) => { if (logout && ex == null) { control.webBrowser.Loaded += new RoutedEventHandler((s, e) => { facebook.getFacebookLoginUri(permissionArray, (loginUri, ex1) => { if (loginUri != null && ex1 == null) { Deployment.Current.Dispatcher.BeginInvoke(() => { control.webBrowser.Navigate(loginUri); }); } else { if (callback != null) { callback(null, ex1); } } }); }); control.webBrowser.LoadCompleted += new LoadCompletedEventHandler((s, e) => { String ss = control.webBrowser.SaveToString(); facebook.getFacebookAccessToken(e.Uri, (accessToken, ex2) => { if (!String.IsNullOrEmpty(accessToken)) { Deployment.Current.Dispatcher.BeginInvoke(() => { popup.IsOpen = false; getFacebookUser((user, ex3) => { if (user != null && ex3 == null) { FacebookSession.save(facebook); } callback(user, ex3); }); }); } else if (ex2 != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { popup.IsOpen = false; if (callback != null) { callback(null, ex2); } }); } }); }); Deployment.Current.Dispatcher.BeginInvoke(() => { popup.Child = control; popup.IsOpen = true; }); } else { if (callback != null) { callback(null, ex); } } }); } catch (Exception) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, "Error occured while logging in facebook.")); } } } else { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_API_KEY_NOT_FOUND, "You didn't set your api key. Please use NetmeraClient.init(apiKey).")); } } }
/// <summary> /// Initiliazes Netmera Facebook utilities with application Id /// </summary> /// <param name="appId">Id of the Facebook application</param> public static void initialize(String appId) { facebook = new Facebook(appId); FacebookSession.restore(facebook); }