我正在使用/重用json.net来获取用户和他/她朋友的喜欢的facebook。我有这个错误:对象引用没有设置为对象的实例
在下面的代码中,我已经解析了facebook json三次,并且我第三次使用它时引发了这个异常......在 methoduserlikes 函数中确切地说...... / p>
我认为问题出现在[var i] .........它在前两次工作正常但是第三次出现了.....
请指出似乎是什么问题......
oAuth.AccessTokenGet(Request["code"]);
global_token = oAuth.Token;
if (oAuth.Token.Length > 0)
{
url = "https://graph.facebook.com/me/likes?access_token=" + oAuth.Token;
url_friends = "https://graph.facebook.com/me/friends?access_token=" + oAuth.Token;
string json = oAuth.WebRequest(oAuthFacebook.Method.GET, url, String.Empty);
string jsonfriends = oAuth.WebRequest(oAuthFacebook.Method.GET, url_friends, String.Empty);
Label1.Text = oAuth.Token.ToString();
JObject likes = JObject.Parse(json);
string id = "";//user id
string name = "";//user likes
JObject friends = JObject.Parse(jsonfriends);
string fid = "";
foreach (var i in likes["data"].Children()) //Loop through the returned friends
{
id = i["id"].ToString().Replace("\"", "");
name = i["name"].ToString().Replace("\"", "");
Label3.Text = Label3.Text + "<br/> " + name;
}
foreach (var i in friends["data"].Children())
{
fid = i["id"].ToString().Replace("\"", "");
methoduserlikes(fid);
}
}
}
}
public void methoduserlikes(string id)
{
Label4.Text = Label4.Text + "<br/> " + id;
string flike = "";
string like_id = "";
string flike_url = "https://graph.facebook.com/" + id + "/likes?access_token=" + global_token;
string jsonfriend_like = oAuth.WebRequest(oAuthFacebook.Method.GET, flike_url, String.Empty);
JObject friend_like = JObject.Parse(jsonfriend_like);
foreach (var i in friend_like["data"].Children())
{
like_id = i["id"].ToString().Replace("\"", "");
**flike = i["name"].ToString().Replace("\"","");** here the exception is raised
Label5.Text = Label5.Text + "<br/> " + flike;
}
}
}