问题
I was trying to get data of wall posts but failed .I am using facebook sdk at codeplex http://facebooksdk.codeplex.com/documentation they have given code to get posts but when i replace my token and change
dynamic result = app.Get("19292868552_118464504835613");
to
dynamic result = app.Get("/me/feed");
the line string fromName = result.from.name;
throws exception that from is not present in result.
then i added some break point and watched them here is picture
you see the difference in two strings named me and result.
me works fine and i can extract any thing i want but result dose not help i have noticed that there is "|" in the string dose that cause the problem.
回答1:
You cannot access from.name as you showed because the data is an array.
could you try this instead.
var fb = new FacebookApp("access_token");
dynamic result = fb.Get("/me/feed");
foreach (dynamic post in result.data)
{
var fromName = post.from.name;
Console.WriteLine(fromName);
}
回答2:
First thing: thing: the operations you are using, doesn't require the facebooksdk library. Its sufficient to use official facebook c# sdk. So, if you think the facebook sdk a little complex, you can only use the official sdk.
Second, You haven't entered the exception message, at least, I can't see. whatever sdk you are using, this is the core facebook api call. So, it shouldn't fail unless you have forgot to implement the access token retrieval part(remember, code and token are 2 different thing, don't get confused between those two). Also, you should take the result as "JSONObject result" , or at least cast it to for getting result. and to show the name use: "result.Dictionary["name"].String" statement instead. Hope this will help you solve your problem. Seems like you are beginning in facebook c# sdk, you can refer to my facebook graph api basics in c# article. Hope this will help too.
Regards
来源:https://stackoverflow.com/questions/4845640/how-to-get-posts-of-user