public static void postfeedGroup(string fbaccesstoken, string fbgrpids, string feedid, string facebookaccountid, int time) { List <string> lstPost = new List <string>(); int lstCout = 0; bool isPosted = false; ShareathonGroupRepository shareagrp = new ShareathonGroupRepository(); Domain.Socioboard.Domain.SharethonGroupPost objshrgrp = new Domain.Socioboard.Domain.SharethonGroupPost(); FacebookClient fb = new FacebookClient(); string[] postid = feedid.TrimEnd(',').Split(','); fb.AccessToken = fbaccesstoken; Random r = new Random(); int length = postid.Length; while (length != lstCout) { int i = r.Next(0, length - 1); if (!lstPost.Contains(postid[i])) { lstPost.Add(postid[i]); lstCout++; string[] group = fbgrpids.Split(','); foreach (var item in group) { isPosted = shareagrp.IsPostExist(item, postid[i], facebookaccountid); if (!isPosted) { string link = "https://www.facebook.com/" + postid[i]; var args = new Dictionary <string, object>(); args["link"] = link; try { dynamic output = fb.Post("v2.0/" + item + "/feed", args); } catch (Exception ex) { Console.Write(ex.StackTrace); } objshrgrp.Id = Guid.NewGuid(); objshrgrp.Facebookaccountid = facebookaccountid; objshrgrp.Facebookgroupid = item; objshrgrp.PostId = postid[i]; objshrgrp.PostedTime = DateTime.UtcNow; shareagrp.AddShareathonPost(objshrgrp); Thread.Sleep(1000 * 15); } } Thread.Sleep(1000 * 60 * time); } } }
private static void PostGroupMultiple(string fbgroupId, int time, string faceaccountId, string[] feedid, int i, ShareathonGroupRepository shareagrp, Domain.Socioboard.Domain.SharethonGroupPost objshrgrp, FacebookClient fb, Dictionary <string, object> args) { if (!shareagrp.IsPostExist(fbgroupId, feedid[i], faceaccountId)) { try { dynamic output = fb.Post("v2.0/" + fbgroupId + "/feed", args); } catch (Exception ex) { Console.Write(ex.StackTrace); } objshrgrp.Id = Guid.NewGuid(); objshrgrp.Facebookaccountid = faceaccountId; objshrgrp.Facebookgroupid = fbgroupId; objshrgrp.PostId = feedid[i]; shareagrp.AddShareathonPost(objshrgrp); Thread.Sleep(1000 * 60 * time); } }