/// <summary> /// /// </summary> /// <param name="accessToken"></param> /// <param name="id"></param> /// <param name="timeInterVal"></param> public static void SchedulePagePost(string accessToken, string destinationPageId, string sourcePageId, int timeInterVal) { try { var timeIncrementer = 1; var cursorNext = string.Empty; do { var feeds = Fbpages.getFacebookPageRecentPost(accessToken, sourcePageId, cursorNext); if (string.IsNullOrEmpty(feeds) || feeds.Equals("[]")) { continue; } var fbPageNotes = JObject.Parse(feeds); try { cursorNext = fbPageNotes["paging"]["next"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.Message); cursorNext = "0"; } foreach (var obj in JArray.Parse(fbPageNotes["data"].ToString())) { try { var postId = obj["id"].ToString(); postId = postId.Split('_')[1]; var timestamp = DateExtension.ConvertToUnixTimestamp(DateTime.UtcNow.AddMinutes(timeInterVal * timeIncrementer)); var link = "https://www.facebook.com/" + sourcePageId + "/posts/" + postId; var pageAccessToken = FacebookApiHelper.GetPageAccessToken(destinationPageId, accessToken, string.Empty); var status = FacebookApiHelper.PublishPostOnSchedule(string.Empty, accessToken, destinationPageId, link, timestamp.ToString(CultureInfo.InvariantCulture)); if (status) { timeIncrementer++; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } while (cursorNext != "0"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void schedulePage_Post(string accessToken, string id, int TimeInterVal) { try { int i = 1; string curser_next = string.Empty; do { string feeds = Fbpages.getFacebookPageRecentPost(accessToken, id, curser_next); string feedId = string.Empty; if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]")) { JObject fbpageNotes = JObject.Parse(feeds); try { curser_next = fbpageNotes["paging"]["next"].ToString(); } catch (Exception ex) { curser_next = "0"; } foreach (JObject obj in JArray.Parse(fbpageNotes["data"].ToString())) { try { string feedid = obj["id"].ToString(); feedid = feedid.Split('_')[1]; double timestamp = Helper.DateExtension.ConvertToUnixTimestamp(DateTime.UtcNow.AddMinutes(TimeInterVal * i)); string link = "https://www.facebook.com/" + id + "/posts/" + feedid; string ret = Fbpages.schedulePage_Post(accessToken, link, timestamp.ToString()); if (!string.IsNullOrEmpty(ret)) { i++; } } catch { } } } } while (curser_next != "0"); } catch (Exception ex) { } }