2016-01-07 106 views
0

我將Facebook身份驗證添加到我的新ASP.NET 5 MVC 6應用程序中。我下面這篇文章: https://docs.asp.net/en/latest/security/authentication/sociallogins.htmlFacebook身份驗證的其他權限

添加以下代碼片段到我的啓動配置方法,它讓我對用戶的基本信息。

app.UseFacebookAuthentication(options => 
{ 
    options.AppId = "myFacebookAppId"; 
    options.AppSecret = "myFacebookSecret"; 
}); 

我想從用戶的出生日期只需要一個Facebook的請求。

我在哪裏添加這個代碼?

回答

0

options類有一個Fields屬性;

/// <summary> 
/// The list of fields to retrieve from the UserInformationEndpoint. 
/// https://developers.facebook.com/docs/graph-api/reference/user 
/// </summary> 
public IList<string> Fields { get; } 

birthday添加到字段屬性。

+0

值得一提的是,簡單地增加了'birthday'場到'Fields'屬性(即不存在RC1,BTW),是遠遠不夠的:你還需要請求' user_birthday'範圍。 – Pinpoint

0

要請求出生的用戶的日期,你需要:

  • 更新Scope財產,以確保user_birthday範圍由Facebook的中間件創建的授權請求時包括在內。如果您不添加user_birthday範圍,圖形API將永遠不會返回用戶的出生日期的:options.Scope.Add("user_birthday");

  • 更新Fields屬性包括:birthday領域,通過@blowdart的建議:options.Fields.Add("birthday");

但要注意的是,Fields屬性不會在ASP.NET 5 RC1(最新版本ATM)存在。另外,you can also replace the UserInformationEndpoint property to include the fields you need

options.UserInformationEndpoint = "https://graph.facebook.com/me?fields=birthday,email,name"; 
+0

@薩姆你有機會嘗試一下嗎? – Pinpoint