I have this code which is somewhat working. the problem is that I cannot figure out how to show each seperate employer for my friends.
namespace WebApplication1.Site
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var accessToken = "access token";
var client = new FacebookClient(accessToken);
dynamic myInfo = client.Get("me/friends", new { fields = "name,id,work" });
foreach (dynamic friend in myInfo.data)
{
Response.Write("Name: " + friend.name + " Employer: " + friend.work + "<br/><br/>");
}
}
}
}
When I try to use this code:
Response.Write("Name: " + friend.name + "<br/>Employer: " + friend.work.employer + "<br/><br/>");
I get this result “‘Facebook.JsonArray’ does not contain a definition for ’employer’“
HELP! (Using .net 4.5 if it matters)
In your response,
friend.workis an array, potentially with multiple employers (present and/or future) per friend. Alsofriend.work.employeris also an array, containing the id and name of each employer.See here: https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends%3Ffields%3Dname%2Cid%2Cwork
I’m not that familiar with c#, but I’m guessing you can’t directly write an array, so you’ll need to loop through
friend.workwith aforeachloop and concatenate each returnedemployer.nameinto a string.You may run into trouble because not all friends have configured their work history, so you may have friends without
friend.work. You’ll need to deal with this possibility in your code.