title: How do I implement Facebook Authentication using Parse in Xamarin Cross Platform Solution?
body: <p>I'm creating a cross platform mobile application for a local food truck for my senior project. I specifically want to use Parse for it's User class because there will be multiple roles. I'm having trouble with implementing Facebook authentication with Parse. For some reason, I keep getting an error that I can't access JsonValue. Can anyone give me some guidance?
  Here is a link to my git repository, if that would help. <a href="https://github.com/mkmcgreal/FoodTruck.git" rel="nofollow">https://github.com/mkmcgreal/FoodTruck.git</a></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using Android.App;
  using Android.Content;
  using Android.Runtime;
  using Android.Views;
  using Android.Widget;
  using Android.OS;
  
  using Parse;
  using System.Json;
  using System.Threading.Tasks;
  using Xamarin.Auth;
  
  namespace FoodTruck.Droid
  {
      [Activity (Label = "Food Truck", MainLauncher = true, Icon = "@mipmap/icon")]
      public class MainActivity : Activity
      {
          //int count = 1;
          public void LoginToFacebook (bool allowCancel)
          {
  
              var auth = new OAuth2Authenticator (
                  clientId: "**************",
                  scope: "",
                  authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
                  redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));
  
              auth.AllowCancel = allowCancel;
  
              // If authorization succeeds or is canceled, .Completed will be fired.
              auth.Completed += LoginComplete;
  
  //          UIViewController vc = auth.GetUI ();
  //          PresentViewController (vc, true, null);
          }
  
          public async void LoginComplete( object sender, AuthenticatorCompletedEventArgs e )
          {
              // We presented the UI, so it's up to us to dismiss it.
              //DismissViewController (true, null);
  
              if (!e.IsAuthenticated) {
                  Console.WriteLine ("Not Authorised");
                  return;
              }
  
              var accessToken = e.Account.Properties["access_token"].ToString();
              var expiresIn = Convert.ToDouble(e.Account.Properties["expires_in"]);
              var expiryDate = DateTime.Now + TimeSpan.FromSeconds( expiresIn );
  
              // Now that we're logged in, make a OAuth2 request to get the user's id.
              var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account);
              request.GetResponseAsync().ContinueWith (t =&gt; {
                  var builder = new AlertDialog.Builder (this);
                  if (t.IsFaulted) 
                  {
                      builder.SetTitle ("Error");
                      builder.SetMessage (t.Exception.Flatten().InnerException.ToString());
                  } 
                  else if (t.IsCanceled)
                  {
                      builder.SetTitle ("Task Canceled");
                  ]
                  else {
                  var obj = JsonValue.Parse (t.Result.GetResponseText());
                  var id = obj["id"].ToString().Replace("\"","");
                  var user = ParseFacebookUtils.LogInAsync(id, accessToken,expiryDate);
  
                  builder.SetTitle ("Logged in");
                  builder.SetMessage ("Name: " + obj["name"]);
                  }
              }
          }
  
          protected override void OnCreate (Bundle bundle)
          {
              Xamarin.Insights.Initialize (global::FoodTruck.Droid.XamarinInsights.ApiKey, this);
  
              base.OnCreate (bundle);
              SetContentView (Resource.Layout.Main);
              StartActivity (auth.GetUI (this));
  
  //          var facebook = FindViewById&lt;Button&gt; (Resource.Id.FacebookButton);           
  //          facebook.Click += delegate { LoginToFacebook(true);};
  //
  //          var facebookNoCancel = FindViewById&lt;Button&gt; (Resource.Id.FacebookButtonNoCancel);
  //          facebookNoCancel.Click += delegate { LoginToFacebook(false);};
              //};
          }
      }
  }
  </code></pre>