Dotnetopenauth, get email from facebook area

I have a question that, I, supersipically, could not find the answer to the search.

If I ask for the email address of users from facebook, for example:

var scope = new List<string>(); scope.Add("email"); FbClient.RequestUserAuthorization(scope); 

How to get it? I could not find a clear option for this on FacebookGraph.

+4
source share
3 answers

Nearby, as I can say, the FacebookGraph object, which is in the examples from DotNetOpenAuth, does not support changing the fields you receive. However, since the WebRequest that it requests returns a JSON string, you can parse it yourself (or use a different JSON parser). This is exactly what I did using 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. } } 

Note that you indicate which fields you want to send back as part of the WebRequest URI. The fields that are available can be found at https://developers.facebook.com/docs/reference/api/user/

+3
source

Using DNOA This answer did it for me.

Just added the following:

 var scope = new List<string>(); scope.Add("email"); client.RequestUserAuthorization(scope); 

and the next on the facebook graph.

 [DataMember(Name = "email")] public string EMail { get; set; } 
+2
source

What you wrote above seems to require authorization from the user so that your application can return email when requesting a user object. To request a user object, you get HTTP Get on https://graph.facebook.com/me . Try using the API graphical analyzer tool https://developers.facebook.com/tools/explorer

0
source

Source: https://habr.com/ru/post/1390456/


All Articles