Ciao a tutti,
per studio sto provando ad eseguire il login a facebook.
Oltre ad aver visto il sistema che rilascia visual studio di default sto provando con questo esempio trovato si msdn
https://blogs.msdn.microsoft.com/nickpinheiro/2015/02/28/facebook-login-with-asp-net-web-forms/ Tutto mi funziona correttamente, ma vorrei apportare delle modifiche ovvero vorrei capire alcune cose, in particolare ora mi sto soffermando sul Deserialize (anche se non c'entra nulla con il login)
Questo è il codice che sto usando
Uri targetUserUri = new Uri("https://graph.facebook.com/me?fields=id,name,gender,link,first_name,last_name&access_token=" + accessToken);
HttpWebRequest user = (HttpWebRequest)HttpWebRequest.Create(targetUserUri);
// Read the returned JSON object response
StreamReader userInfo = new StreamReader(user.GetResponse().GetResponseStream());
string jsonResponse = string.Empty;
jsonResponse = userInfo.ReadToEnd();
// Deserialize and convert the JSON object to the Facebook.User object type
JavaScriptSerializer sr = new JavaScriptSerializer();
string jsondata = jsonResponse;
Facebook.User converted = sr.Deserialize<Facebook.User>(jsondata);
// Write the user data to a List
List<Facebook.User> currentUser = new List<Facebook.User>();
currentUser.Add(converted);
// Return the current Facebook user
return currentUser;
Facebook mi ritorna un json
{
"id": "1020EEEEE00796",
"name": "Pibe",
"gender": "male",
"cover": {
"id": "10208XXXXX9461",
"offset_y": 0,
"source": "https://scontent.xx.fbcdn.net/v/t31.0-8/q85/s720x720/13641028_10208347UUUUU_2819440007590905659_o.jpg?oh=61c4d9e9d8a288433f05fd076b83b2ec&oe=59215688"
},
"picture": {
"data": {
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/15940954_102097OOOOOPPPPP993_4887467687573942363_n.jpg?oh=02XXXX896ad3d481c6d2effe1581f410&oe=59YYY0C"
}
},
"link": "https://www.facebook.com/app_scoped_user_id/1020XXXX300796/",
"first_name": "Diego",
"last_name": "Maradona"
}
In models ho una classe in cui setto questi valori
public class Facebook
{
public class User
{
public string id { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public string link { get; set; }
public string username { get; set; }
public string gender { get; set; }
public string picture { get; set; }
public string cover { get; set; }
}
}
In questo punto praticamente
List<Facebook.User> currentUser = new List<Facebook.User>();
currentUser.Add(converted);
si vanno a riempire gli elementi contenuti in currentUser
Non riesco a prendere il valore cover e picture, ovvero il valore source di cover e url di picture.
C'è un sistema con questo codice fornito di prendere anche questi dati o posso in qualche altro modo usare il Deserialize?
Grazie