Created
May 2, 2016 19:24
-
-
Save georgechond94/d402ea77173753e75cc23f42c33b18e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public MobileServiceClient client; | |
public MobileServiceUser user; | |
public MainPage() | |
{ | |
this.InitializeComponent(); | |
} | |
protected override void OnNavigatedTo(NavigationEventArgs e) | |
{ | |
base.OnNavigatedTo(e); | |
client = new MobileServiceClient("https://uwpstories.azurewebsites.net"); | |
} | |
private async void Login_Click(object sender, RoutedEventArgs e) | |
{ | |
Button button = sender as Button; | |
try | |
{ | |
switch (button.Content as string) | |
{ | |
case "Facebook": | |
user = await client.LoginAsync(MobileServiceAuthenticationProvider.Facebook); | |
break; | |
case "Google": | |
user = await client.LoginAsync(MobileServiceAuthenticationProvider.Google); | |
break; | |
case "Microsoft Account": | |
user = await client.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount); | |
break; | |
case "Twitter": | |
user = await client.LoginAsync(MobileServiceAuthenticationProvider.Twitter); | |
break; | |
} | |
} | |
catch (Exception) | |
{ | |
} | |
if (user != null) | |
{ | |
var userInfo = await client.InvokeApiAsync<UserInfo>("UserInfo",HttpMethod.Get,null); | |
userName.Text = userInfo.Name; | |
var httpclient = new HttpClient(); | |
var bytes = await httpclient.GetByteArrayAsync(userInfo.ImageUri); | |
var bi = new BitmapImage(); | |
await | |
bi.SetSourceAsync( | |
new MemoryStream(bytes).AsRandomAccessStream()); | |
userImage.Source = bi; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment