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/找到 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 会话最佳实践
- rest – 在ASP.NET Core中实现“JSON Merge Patch” – 最好
- asp.net-mvc – 无法将值NULL插入“Discriminator”列,表’
- asp.net – 使用MVC 4的.NET 4.5数据访问应用程序块
- asp.net – 如何在设计模式下打开RDLC
- 经典Asp中的多行字符串
- asp.net – 消息处理程序和Http模块?
- asp.net-mvc – 如何在ASP.Net Identity上获取OWIN上下文?
- asp.net-mvc – 允许使用数字中的点和逗号,而不仅仅是小数
- kendo-ui – Kendo grid在最后一页,最后一行位置插入新记录
推荐文章
站长推荐
热点阅读