.NET에서 Facebook SDK를 사용하여 페이지에서 Facebook 게시물을 가져와 앱에 표시합니다. 게시물을 얻을Json 개체를 iEnumerable로 변환
public class Posts
{
public string id { get; set; }
public string Name { get; set; }
public string Message { get; set; }
public Uri PictureUri { get; set; }
}
public class FacebookPostsData
{
private static ObservableCollection<Posts> posts = new ObservableCollection<Posts>();
public static ObservableCollection<Posts> Posts
{
get
{
return posts;
}
}
}
그리고 다음 코드를 : 나는 다음과 같은 클래스가
FacebookClient fb = new FacebookClient(App.AccessToken);
dynamic postsTaskResult = await fb.GetTaskAsync("/mypage?fields=posts");
var result = (IDictionary<string, object>)postsTaskResult;
var data = (IEnumerable<object>)result["posts"];
foreach (var item in data)
{
var post = (IDictionary<string, object>)item;
FacebookPostsData.Posts.Add(new Posts { Name = (string)post["name"], id = (string)post["id"], Message = (string)post["message"], PictureUri = new Uri(string.Format("{0}", (string)post["picture"])) });
}
Frame.Navigate(typeof(Pages.next));
그러나, [ "게시물"] 결과를 JSON 개체를 반환하고 나는 다음과 같은 오류가 발생합니다.
Unable to cast object of type 'Facebook.JsonObject' to type 'System.Collections.Generic.IEnumerable`1[MyProject.ViewModel.Posts]'.
개체 변환 방법에 대한 아이디어가 있으십니까?
목적은 다음과 같은 페이스 북의 게시물은 다음과 같습니다
"id": "339150749455906",
"posts": {
"data": [
{
"id": "339150749455906_545370565500589",
"from": {
"category": "Food/beverages",
"name": "Pepsi",
"id": "339150749455906"
},
"story": "Pepsi updated their cover photo.",
"picture": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash3/942740_545370555500590_46289134_s.jpg",
"link": "http://www.facebook.com/photo.php?fbid=545370555500590&set=a.365573920146922.72816.339150749455906&type=1&relevant_count=1",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/339150749455906/posts/545370565500589"
},
{
"name": "Like",
"link": "http://www.facebook.com/339150749455906/posts/545370565500589"
}
],
"privacy": {
"value": ""
},
는 기본적으로 나는 게시물의 데이터를 필요로하지만 [ "데이터"] 대신 게시물의 결과를 작성하는 경우, 나는이 오류에서 테스트되지 않은 코드 사전에. –