Esempio n. 1
0
        /// <summary>
        /// Fetches data returned by login dialog from callback uri. Creates and saves new AccessTokenData object to current session.
        /// Calls getLoginStatus internally to fill AccessTokenData with such values as FacebookId and CurrentPermissions
        /// </summary>
        /// <param name="uri">Callback uri of login dialog</param>
        private static Task <AccessTokenData> FetchLoginUriAsync(Uri uri)
        {
            var tcs = new TaskCompletionSource <AccessTokenData>();

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                var oauthResult = FbClient.ParseOAuthCallbackUrl(uri);
                if (oauthResult.IsSuccess)
                {
                    var tempToken = new AccessTokenData
                    {
                        AccessToken = oauthResult.AccessToken,
                        Expires     = oauthResult.Expires
                    };

                    tcs.SetResult(tempToken);
                }
                else
                {
                    tcs.SetException(new Exception(oauthResult.Error));
                }
            });

            return(tcs.Task);
        }
 private void WebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
 {
     try
     {
         var callback = webBrowser.Source;
         var oauth    = FbClient.ParseOAuthCallbackUrl(callback);
         FbClient.AccessToken = oauth.AccessToken;
         FbAccountLoggedIn    = true;
         browserWindow.Close();
         MessageBox.Show("Authentication successful. You can now post recipes to Facebook.");
     }
     catch (Exception ex)
     {
         return;
     }
 }