Skip to content

Instantly share code, notes, and snippets.

@ericsk
Created July 6, 2012 16:32
Show Gist options
  • Save ericsk/3061197 to your computer and use it in GitHub Desktop.
Save ericsk/3061197 to your computer and use it in GitHub Desktop.
使用 WebAuthenticationBroker 做 Facebook 身份驗證 (C#)
using Windows.Foundation;
using Windows.Security.Authentication.Web;
// 組合授權的 URL
var authUrl = new Uri(string.Format(
"https://www.facebook.com/dialog/oauth?client_id={0}&redirect_uri={1}&response_type=token&display=popup&scope={2}",
"<你應用程式的 ID>",
Uri.EscapeDataString("https://www.facebook.com/connect/login_success.html"),
"<權限列表,以 , 隔開>"));
// 回呼 URL
var callbackUrl = new Uri("https://www.facebook.com/connect/login_success.html");
// 呼叫 WebAuthenticationBroker
var result = await WebAuthenticationBroker.authenticateAsync(
WebAuthenticationOptions.none, authUrl, callbackUrl);
// 完成授權的動作,檢查授權是否成功
if (result.ResponseStatus == WebAuthenticationStatus.Success) {
// 成功授權,從 result.ResponseData 中取得 access_token 以及 expires_in 的值
} else {
// 處理發生錯誤的狀況
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment