Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my project I just listened for the WebView's navigated event. If it happens, it means that user did something on the login page (i.e. pressed login button). Then I parsed the uri of the page you mentioned which should contain OAuth callback url, if it is correct and the result is success I redirect manually to the correct page:</p> <pre><code> //somewhere in the app private readonly FacebookClient _fb = new FacebookClient(); private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) { FacebookOAuthResult oauthResult; if (!_fb.TryParseOAuthCallbackUrl(e.Uri, out oauthResult)) { return; } if (oauthResult.IsSuccess) { var accessToken = oauthResult.AccessToken; //you have an access token, you can proceed further FBLoginSucceded(accessToken); } else { // errors when logging in MessageBox.Show(oauthResult.ErrorDescription); } } </code></pre> <p>If you abstract logging in an async function, you expect it to behave asynchronously, so events are ok.</p> <p>Sorry for my English.</p> <p>The code for the full page:</p> <pre><code>public partial class LoginPageFacebook : PhoneApplicationPage { private readonly string AppId = Constants.FacebookAppId; private const string ExtendedPermissions = "user_birthday,email,user_photos"; private readonly FacebookClient _fb = new FacebookClient(); private Dictionary&lt;string, object&gt; facebookData = new Dictionary&lt;string, object&gt;(); UserIdentity userIdentity = App.Current.Resources["userIdentity"] as UserIdentity; public LoginPageFacebook() { InitializeComponent(); } private void webBrowser1_Loaded(object sender, RoutedEventArgs e) { var loginUrl = GetFacebookLoginUrl(AppId, ExtendedPermissions); webBrowser1.Navigate(loginUrl); } private Uri GetFacebookLoginUrl(string appId, string extendedPermissions) { var parameters = new Dictionary&lt;string, object&gt;(); parameters["client_id"] = appId; parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html"; parameters["response_type"] = "token"; parameters["display"] = "touch"; // add the 'scope' only if we have extendedPermissions. if (!string.IsNullOrEmpty(extendedPermissions)) { // A comma-delimited list of permissions parameters["scope"] = extendedPermissions; } return _fb.GetLoginUrl(parameters); } private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) { if (waitPanel.Visibility == Visibility.Visible) { waitPanel.Visibility = Visibility.Collapsed; webBrowser1.Visibility = Visibility.Visible; } FacebookOAuthResult oauthResult; if (!_fb.TryParseOAuthCallbackUrl(e.Uri, out oauthResult)) { return; } if (oauthResult.IsSuccess) { var accessToken = oauthResult.AccessToken; FBLoginSucceded(accessToken); } else { // user cancelled MessageBox.Show(oauthResult.ErrorDescription); } } private void FBLoginSucceded(string accessToken) { var fb = new FacebookClient(accessToken); fb.GetCompleted += (o, e) =&gt; { if (e.Error != null) { Dispatcher.BeginInvoke(() =&gt; MessageBox.Show(e.Error.Message)); return; } var result = (IDictionary&lt;string, object&gt;)e.GetResultData(); var id = (string)result["id"]; userIdentity.FBAccessToken = accessToken; userIdentity.FBID = id; facebookData["Name"] = result["first_name"]; facebookData["Surname"] = result["last_name"]; facebookData["Email"] = result["email"]; facebookData["Birthday"] = DateTime.Parse((string)result["birthday"]); facebookData["Country"] = result["locale"]; Dispatcher.BeginInvoke(() =&gt; { BitmapImage profilePicture = new BitmapImage(new Uri(string.Format("https://graph.facebook.com/{0}/picture?type={1}&amp;access_token={2}", id, "square", accessToken))); facebookData["ProfilePicture"] = profilePicture; userIdentity.FBData = facebookData; userIdentity.ProfilePicture = profilePicture; ARLoginOrRegister(); }); }; fb.GetAsync("me"); } private void ARLoginOrRegister() { WebService.ARServiceClient client = new WebService.ARServiceClient(); client.GetUserCompleted += client_GetUserCompleted; client.GetUserAsync((string)facebookData["Email"]); client.CloseAsync(); } void client_GetUserCompleted(object sender, WebService.GetUserCompletedEventArgs e) { if (e.Result == null) NavigationService.Navigate(new Uri("/RegisterPageFacebook.xaml", UriKind.RelativeOrAbsolute)); else if (e.Result.AccountType != (int)AccountType.Facebook) { MessageBox.Show("This account is not registered with facebook!"); NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.RelativeOrAbsolute)); } else { userIdentity.Authenticated += userIdentity_Authenticated; userIdentity.FetchARSocialData((string)facebookData["Email"]); } } void userIdentity_Authenticated(bool success) { NavigationService.Navigate(new Uri("/MenuPage.xaml", UriKind.RelativeOrAbsolute)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload