/** * Makes a call to the Facebook APIs to read all posts and unpublished posts from a page, and calls the provided * callback function when the API call is complete. * * Note that the callback function expects an array of objects in the following format: * { message: "a message", datePosted: "2017-08-26 11:36:00", isPublished: false } * (The date format doesn't need to match exactly but should include the date and time.) * * Parameters: * accessToken: The Facebook access token for use in querying the API * * This function should not return anything. */ public static PageManagerPagePostsInfo ReadPost(string pageId, string accessToken, string nextPageUrl = "") { var result = new PageManagerPagePostsInfo(); var url = string.Empty; HttpResponseMessage response = null; if (!string.IsNullOrEmpty(nextPageUrl)) { response = HttpUtility.GetRequest(nextPageUrl); } else { var resource = pageId + "/posts"; var fields = "comments,message,created_time,reactions"; response = HttpUtility.GetRequest(accessToken, resource, string.Empty, fields); } if (response != null && response.IsSuccessStatusCode) { var responseContent = response.Content; var apiResponse = Newtonsoft.Json.Linq.JObject.Parse(responseContent.ReadAsStringAsync().Result); foreach (var feed in apiResponse["data"]) { result.Data.Add( new PageManagerPagePost { Message = (string)feed["message"], DatePosted = (string)feed["created_time"], Id = (string)feed["id"], NumberOfComments = ((Newtonsoft.Json.Linq.JObject)feed["comments"] != null ? ((Newtonsoft.Json.Linq.JArray)feed["comments"]["data"]).Count : 0), NumberOfReactions = ((Newtonsoft.Json.Linq.JObject)feed["reactions"] != null ? ((Newtonsoft.Json.Linq.JArray)feed["reactions"]["data"]).Count : 0), IsPublished = true } ); } result.NextPageUrl = (apiResponse["paging"]["next"] != null ? (string)apiResponse["paging"]["next"] : null); } return(result); }
public static PageManagerPagePostsInfo ReadUnpublishedPosts(string pageId, string accessToken, string nextPageUrl = "") { var result = new PageManagerPagePostsInfo(); HttpResponseMessage response = null; if (!string.IsNullOrEmpty(nextPageUrl)) { response = HttpUtility.GetRequest(nextPageUrl); } else { var resource = pageId + "/promotable_posts"; var filter = "is_published=false"; response = HttpUtility.GetRequest(accessToken, resource, filter); } if (response != null && response.IsSuccessStatusCode) { var responseContent = response.Content; var apiResponse = Newtonsoft.Json.Linq.JObject.Parse(responseContent.ReadAsStringAsync().Result); foreach (var feed in apiResponse["data"]) { result.Data.Add( new PageManagerPagePost { Message = (string)feed["message"], DatePosted = (string)feed["created_time"], Id = (string)feed["id"], IsPublished = false } ); } result.NextPageUrl = (apiResponse["paging"]["next"] != null ? (string)apiResponse["paging"]["next"] : null); } return(result); }