有一个问题,我在四处搜索时出乎意料地找不到答案。
如果我请求来自 facebook 的用户电子邮件,例如:
var scope = new List<string>();
scope.Add("email");
FbClient.RequestUserAuthorization(scope);
如何找回它?我在 FacebookGraph 中找不到明确的选项。
最佳答案
据我所知,DotNetOpenAuth 示例中的 FacebookGraph 对象不支持更改您接收到的字段。但是,由于它提示的 WebRequest 正在返回一个 JSON 字符串,您可以自己解析它(或使用另一个 JSON 解析器)。这正是我所做的,使用 NewtonSoft.Json.dll :
//as part of the uri for the webrequest, include all the fields you want to use
var request = WebRequest.Create("https://graph.facebook.com/me?fields=email,name&access_token=" + Uri.EscapeDataString(authorization.AccessToken));
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
System.IO.StreamReader streamReader = new System.IO.StreamReader(responseStream, true);
string MyStr = streamReader.ReadToEnd();
JObject userInfo = JObject.Parse(MyStr);
//now you can access elements via:
// (string)userInfo["name"], userInfo["email"], userInfo["id"], etc.
}
}
请注意,您指定要作为 WebRequest URI 的一部分发回的字段。可以在 https://developers.facebook.com/docs/reference/api/user/ 找到可用的字段
关于asp.net - Dotnetopenauth,从 facebook 范围检索电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8822099/