使用MVC 4的Facebook oAuth用户详细信息

时间:2013-09-08 00:34:38

标签: facebook asp.net-mvc-4 oauth twitter-oauth facebook-oauth

我正在使用OAuthWebSecurityMVC来允许我网站的用户使用Facebook的oAuth登录。一切正常,我有一个测试用户认证很好。

我的问题是基于Facebook可以提供的细节。我目前正在使用以下内容返回用户详细信息...

AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication();

这将给出以下详细信息:

  • 用户名(电子邮件)
  • ProviderUserId

我还得到一个ExternalData对象,其中包含:

  • 用户名
  • 名称
  • 性别

您知道是否有可能获得更多数据,可能是DoB,照片等?

1 个答案:

答案 0 :(得分:1)

请原谅我没有给我完整答案。我只是提供一个链接。请检查

http://blue-and-orange.net/articles/facebook/displaying-facebook-user-data-in-aspnet-mvc-4/

这里解释了一切。

有关设置权限,您可以阅读本文档 https://developers.facebook.com/docs/facebook-login/permissions/

如果您要求提供用户的电子邮件地址,但从未向他们询问过电子邮件地址'如果允许,您将收到OAuth错误,如下所示。

try {
var client = new FacebookClient("my_access_token");
dynamic result = client.Get("me/email");
var email = (string)result.email;

}

catch (FacebookOAuthException) {
    // The access token expired or the user 
    // has not granted your app 'email' permission.
    // Handle this by redirecting the user to the
    // Facebook authenticate and ask for email permission.
}