加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – Dotnetopenauth,从facebook范围检索电子邮件

发布时间:2020-12-16 06:23:54 所属栏目:asp.Net 来源:网络整理
导读:有一个问题我在搜索时无法找到答案. 如果我从Facebook请求用户发送电子邮件,例如: var scope = new Liststring(); scope.Add("email"); FbClient.RequestUserAuthorization(scope); 我该如何检索它?我无法在FacebookGraph中找到明确的选项. 解决方法 据我
有一个问题我在搜索时无法找到答案.

如果我从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/找到

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读