Created
May 25, 2014 09:48
-
-
Save Tapanila/7968c1fdd229ae15a0d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private async void Authenticate() | |
| { | |
| //Facebook Authentication Uri | |
| var facebookUri = "https://www.facebook.com/dialog/oauth"; | |
| //Standard redirect uri for desktop/non-web based apps | |
| var redirectUri = | |
| "https://www.facebook.com/connect/login_success.html"; | |
| //Place your appclient id here | |
| var clientId = ""; | |
| //The type of token that can be requested | |
| var responseType = "token"; | |
| //Response pattern | |
| var pattern = string.Format("{0}#access_token={1}&expires_in={2}", | |
| redirectUri, "(?.+)", "(?.+)"); | |
| //Access scope wanted | |
| var scope = "read_stream"; | |
| try | |
| { | |
| String FacebookURL = "https://www.facebook.com/dialog/oauth?" + | |
| "client_id=" + clientId + "&redirect_uri=" + | |
| Uri.EscapeUriString(redirectUri) + "&scope=" + scope + | |
| "&display=touch&response_type=" + responseType; | |
| System.Uri StartUri = new Uri(FacebookURL); | |
| System.Uri EndUri = new Uri(redirectUri); | |
| WebAuthenticationResult WebAuthenticationResult = | |
| await WebAuthenticationBroker.AuthenticateAsync( | |
| WebAuthenticationOptions.None, | |
| StartUri, | |
| EndUri); | |
| if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) | |
| { | |
| //Authenticated succesfully | |
| var response = WebAuthenticationResult.ResponseData.ToString(); | |
| } | |
| else if | |
| (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp) | |
| { | |
| //Handle HTTP error | |
| } | |
| else | |
| { | |
| //Authentication failed | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| //Handle error | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment