错误:在 asp.net 中解析 facebook JSON 时,未将对象引用设置为对象的实例
我正在使用/重用 json.net 来获取用户及其朋友的 facebook 点赞。我遇到了这个错误:对象引用未设置为对象的实例
在下面的代码中,我已经解析了 facebook json 三次,并且在第三次使用它时引发了这个异常....在 准确地说,methoduserlikes 函数...
我认为问题出在 [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;
}
}
}
I am using/reusing json.net to get facebook likes of a user and his/her friend's like. I am having this error : Object reference not set to an instance of an object
In the following code, I have parsed facebook json three times and I have this exception raised the third time I have used it....in the methoduserlikes function to be precise...
I think the problem is in [var i].........it works fine the first two times but exeception occurs third time.....
kindly point out what seems to be the problem.....
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;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论