The LoginAsync method returns a MobileServiceUser object. This object gives you the authentication token (MobileServiceAuthenticationToken property) and the User ID (UserId property). This last one is formatted with the following pattern : « [provider]:[AppUserID]. You can use this AppUserID with Facebook Open Graph to retrieve some basic information about the logged in user.
For instance, a call to https://graph.facebook.com/[UserAppId] will returned the following json :
{
try
{
var user = await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.Facebook);
HttpClient client = new HttpClient();
string url = String.Format("https://graph.facebook.com/{0}", user.UserId.Split(':')[1]);
string json = await client.GetStringAsync(url);
FacebookUser fbUser = await JsonConvert.DeserializeObjectAsync<FacebookUser>(json);
MessageDialog md = new MessageDialog("Welcome " + fbUser.Name);
await md.ShowAsync();
}
catch (Exception)
{
MessageDialog md = new MessageDialog("Authentication failed");
md.ShowAsync();
}
}
That’s it. In this first part, we’ve seen how to configure a mobile service to work with Facebook and how to integrate it into a Windows Store Apps. This is a pretty cool, but also quite limited in term of functionality. We wil now go further with the Facebook SDK for .NET.