async public Task <AppLink> GetAppLinkAsync(string accessToken, string sourceUrl) { FacebookClient _client = new FacebookClient(accessToken); String finalUrl = String.Format("https://graph.facebook.com/v2.0/?ids={0}&type=al&fields=windows,windows_phone,windows_universal", sourceUrl); dynamic appLinkData = await _client.GetTaskAsync(finalUrl); List <Target> targets = new List <Target>(); var outerShell = (IDictionary <string, object>)appLinkData[sourceUrl]; if (outerShell.ContainsKey("windows")) { var windowsArray = (IEnumerable <object>)outerShell["windows"]; var windowsObject = (IDictionary <string, object>)(windowsArray.First()); targets.Add(new Target { Uri = (string)windowsObject["url"], Platform = Platform.Windows, Name = (string)windowsObject["app_name"] }); } if (outerShell.ContainsKey("windows_phone")) { var windowsPhoneArray = (IEnumerable <object>)outerShell["windows_phone"]; var windowsPhoneObject = (IDictionary <string, object>)(windowsPhoneArray.First()); targets.Add(new Target { Uri = (string)windowsPhoneObject["url"], Platform = Platform.WindowsPhone, Name = (string)windowsPhoneObject["app_name"] }); } if (outerShell.ContainsKey("windows_universal")) { var universalArray = (IEnumerable <object>)outerShell["windows_universal"]; var universalObject = (IDictionary <string, object>)(universalArray.First()); targets.Add(new Target { Uri = (string)universalObject["url"], Platform = Platform.Universal, Name = (string)universalObject["app_name"] }); } return(new AppLink { SourceUri = sourceUrl, FallbackUri = sourceUrl, Targets = targets }); }
internal async Task <FacebookSession> LoginAsync(string permissions, bool force) { if (LoginInProgress) { throw new InvalidOperationException("Login in progress."); } LoginInProgress = true; try { var session = FacebookSessionCacheProvider.Current.GetSessionData(); if (session == null) { // Authenticate var authResult = await PromptOAuthDialog(permissions, WebAuthenticationOptions.None); FacebookClient client = new FacebookClient(authResult.AccessToken); var parameters = new Dictionary <string, object>(); parameters["fields"] = "id"; var result = await client.GetTaskAsync("me", parameters); var dict = (IDictionary <string, object>)result; session = new FacebookSession { AccessToken = authResult.AccessToken, Expires = authResult.Expires, FacebookId = (string)dict["id"], }; } else { // Check if we are requesting new permissions bool newPermissions = false; if (!string.IsNullOrEmpty(permissions)) { var p = permissions.Split(','); newPermissions = session.CurrentPermissions.Join(p, s1 => s1, s2 => s2, (s1, s2) => s1).Count() != p.Length; } // Prompt OAuth dialog if force renew is true or // if new permissions are requested or // if the access token is expired. if (force || newPermissions || session.Expires <= DateTime.UtcNow) { var authResult = await PromptOAuthDialog(permissions, WebAuthenticationOptions.None); if (authResult != null) { session.AccessToken = authResult.AccessToken; session.Expires = authResult.Expires; } } } // Set the current known permissions if (!string.IsNullOrEmpty(permissions)) { var p = permissions.Split(','); session.CurrentPermissions = session.CurrentPermissions.Union(p).ToList(); } // Save session data FacebookSessionCacheProvider.Current.SaveSessionData(session); } catch (Exception x) { string msg = x.Message; } finally { LoginInProgress = false; } return(CurrentSession); }