Skip to content

Instantly share code, notes, and snippets.

@georgechond94
Created May 2, 2016 19:24
Show Gist options
  • Save georgechond94/d402ea77173753e75cc23f42c33b18e3 to your computer and use it in GitHub Desktop.
Save georgechond94/d402ea77173753e75cc23f42c33b18e3 to your computer and use it in GitHub Desktop.
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