internal static void clearTwitterSession(Action <Boolean, Exception> callback) { if (twitter != null && twitter.isSessionValid()) { twitter.setAccessToken(null); twitter.setSecretToken(null); TwitterSession.clear(); clearTwitterCookies(callback); } else { if (callback != null) { callback(true, null); } } }
/// <summary> /// Login with Twitter account /// </summary> /// <param name="callback">Method to be called when login operation finishes</param> public static void login(Action <NetmeraUser, Exception> callback) { String securityToken = NetmeraClient.getSecurityToken(); if (securityToken != null && securityToken.Trim() != "") { Popup popup = new Popup(); LoginUserControl control = new LoginUserControl(); control.webBrowser.Source = null; control.btnCancel.Click += new RoutedEventHandler((s, e) => { if (callback != null) { callback(null, null); } }); try { NetmeraUser.clearSocialSessions((logout, ex) => { if (logout && ex == null) { control.webBrowser.Loaded += new RoutedEventHandler((s, e) => { twitter.getTwitterLoginUri((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) => { if (e.Uri.AbsoluteUri == Twitter.AuthorizeUrl) { String pinHtml = control.webBrowser.SaveToString(); twitter.getTwitterPin(pinHtml, (pin, ex1) => { if (!String.IsNullOrEmpty(pin)) { twitter.getTwitterAccessToken(e.Uri, (accessToken, ex2) => { Deployment.Current.Dispatcher.BeginInvoke(() => { popup.IsOpen = false; if (ex2 != null) { if (callback != null) { callback(null, ex2); } } else { if (!String.IsNullOrEmpty(accessToken)) { getTwitterUser((user, exc) => { if (user != null && exc == null) { TwitterSession.save(twitter); } callback(user, exc); }); } else { login(callback); } } }); }); } }); } }); Deployment.Current.Dispatcher.BeginInvoke(() => { popup.Child = control; popup.IsOpen = true; }); } else { if (callback != null) { callback(null, ex); } } }); } catch (Exception e) { if (callback != null) { callback(null, e); } } } 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).")); } } }
// private static int count = 0; /// <summary> /// Initiliazes twitter object /// </summary> /// <param name="consumerKey">Consumer key of the twitter applicaton</param> /// <param name="consumerSecret"></param> public static void initialize(String consumerKey, String consumerSecret) { twitter = new Twitter(consumerKey, consumerSecret); TwitterSession.restore(twitter); }