public async Task <MeRootObjects> GetInfoUserMe() { Uri uriData = new Uri(RequestParameters.AuthorizationUri); HttpClient httpClient = new HttpClient(); string responseJson = await httpClient.GetStringAsync(uriData); MeRootObjects data = JsonConvert.DeserializeObject <MeRootObjects>(responseJson, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); return(data); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { publicAuthorization = new PublicAuthorization(); UserAuth = new UserAuthorization(); try { var file = await ApplicationData.Current.LocalFolder.GetFileAsync("UserDefault.txt"); TokenInFileUserDefault = await FileIO.ReadTextAsync(file); } catch (Exception) { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("UserDefault.txt"); } if (access_token == null && TokenInFileUserDefault == "") { Logining.Visibility = Visibility.Visible; Logined.Visibility = Visibility.Collapsed; } else { if (TokenInFileUserDefault != "") { access_token = TokenInFileUserDefault; } var file = await ApplicationData.Current.LocalFolder.GetFileAsync("UserDefault.txt"); await FileIO.WriteTextAsync(file, access_token); if (meRootObjects.id == null) { RequestParameters.AuthorizationUri += access_token; meRootObjects = await publicAuthorization.GetInfoUserMe(); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.UriSource = new Uri(meRootObjects.profile_image.large); imgMe.ImageSource = bitmapImage; tblMe.Text = meRootObjects.name; tblCenter.Text = "Download free, beautiful high-quality photos curated by " + meRootObjects.first_name + " ."; if (meRootObjects.bio == null) { tblBio.Text = ""; } else { tblBio.Text = meRootObjects.bio; } if (meRootObjects.location == null) { tblLocation.Text = ""; } else { tblLocation.Text = meRootObjects.location; } tblUser.Text = meRootObjects.username; PivotMe.Header = "@" + meRootObjects.username; UserText = meRootObjects.username; //RequestParameters.AuthorizationUri = "https://api.unsplash.com/me?access_token="; } else { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.UriSource = new Uri(meRootObjects.profile_image.large); imgMe.ImageSource = bitmapImage; tblMe.Text = meRootObjects.name; tblCenter.Text = "Download free, beautiful high-quality photos curated by " + meRootObjects.first_name + " ."; if (meRootObjects.bio == null) { tblBio.Text = ""; } else { tblBio.Text = meRootObjects.bio; } if (meRootObjects.location == null) { tblLocation.Text = ""; } else { tblLocation.Text = meRootObjects.location; } tblUser.Text = meRootObjects.username; PivotMe.Header = "@" + meRootObjects.username; UserText = meRootObjects.username; } Logined.Visibility = Visibility.Visible; Logining.Visibility = Visibility.Collapsed; } }