public string GetFbPageDetails(string url) { try { FacebookClient fb = new FacebookClient(); FacebookAccount _FacebookAccount = new FacebookAccount(); string token = _FacebookAccount.getFbToken(); fb.AccessToken = "CAAKYvwDVmnUBACyqUsvADWoAfBYTxi0kbz2gcw0sDWbBVJCXmIUG6rGez4BFSCE4hKV8eNE86eCD2iOwEWADvYuNlYupZCL4WUAGhFmRIZA6nTkdUOFeiUVHuri571QxhZA3YfSk5YkjhYy81pYtPj9FNM2mENtjCWRr5tN9zWZAKpUkw3gzsXRuEH9ZBTBwZD"; //fb.AccessToken = token; // logger.Error(" GetFbPageDetails: " + fb.AccessToken); dynamic pageinfo = null; try { pageinfo = fb.Get(url); logger.Error("Token 1"); } catch (Exception ex1) { try { fb.AccessToken = "CAAKYvwDVmnUBAFvCcZCQDL53q82jfR5mvgF2whNsFHgR4NmeSSUeRVpdEUpcVVgK1ERs2GZCNhJAwRHtq6MEWiRtBQnxBmZAML6dnwgpsCbjUmyT7ws6EKZBxuWbxhJqjeNCsxhac00b3L9Bf7LLlYa3PG94Uouj7vXZAZC6djZCme5BuszE3vibNFLKQqaLcgZD"; pageinfo = fb.Get(url); logger.Error("Token 2"); } catch (Exception ex2) { try { fb.AccessToken = "CAAKYvwDVmnUBAAR2O9hxFkHzfNG8H6KbQLaiGFMRshJkbttdzhDeprklcb1yaV0rwtC7N8Xz1rsL1cykiRv2ouXtBUFxvOZCNnpFELnQGFV8jGUWjm1GYsZA40IKAORLGoAcSaa2lJkuuSoLBksB8LFPHI4cqW7VVqxgDwZCRwObxqR4Qp9QEDHxa7j1yoZD"; pageinfo = fb.Get(url); logger.Error("Token 3"); } catch (Exception ex3) { try { fb.AccessToken = "CAAKYvwDVmnUBAFtZB8pvVrqYQonmq7MD90oNdoipDc0Te4onP2XlbZAYT4bzOZAKTr8jdhw0P1PclgLOtVxJ9g2qx4vxZAzh2CXqXAZBZAZBwkgWIVjc2B4rcXAp6O5B3gXqd8Ko5ITL9VCZCMOkMZCPc1hBsp0n8zgPt6e3Dd0vaodPBS8nMz7RD"; pageinfo = fb.Get(url); logger.Error("Token 4"); } catch (Exception ex4) { try { fb.AccessToken = "CAAKYvwDVmnUBALvjTAKIrVKnL719aVDB7BmMRn7e08ySJQwHYtLDZBBjx5yBZBaMeJ04lIT8bCzX2A685YLXR9d8PukZCBZA2LiwZAmj6qhMZC8F0od7NBircdMZAOZAD1xukXDhd24RQRvVk9GyJNRmmGTiZAhMJzXBVczH3TlYb37qi8FRXfTGDRTZAyxjyYSt8ZD"; pageinfo = fb.Get(url); logger.Error("Token 5"); } catch (Exception ex5) { logger.Error("Finally :" + fb.AccessToken); logger.Error(ex5.Message); logger.Error(ex5.Message); } } } } } Domain.Myfashion.Domain.AddFacebookPage objAddFacebookPage = new Domain.Myfashion.Domain.AddFacebookPage(); objAddFacebookPage.ProfilePageId = pageinfo["id"]; logger.Error(" pageinfo: " + pageinfo["id"]); return new JavaScriptSerializer().Serialize(objAddFacebookPage); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); return "Something Went Wrong"; } }
public string GetFacebookPages(string code) { string client_id = ConfigurationManager.AppSettings["ClientId"]; string redirect_uri = ConfigurationManager.AppSettings["RedirectUrl"]; string client_secret = ConfigurationManager.AppSettings["ClientSecretKey"]; List<Domain.Myfashion.Domain.AddFacebookPage> lstAddFacebookPage = new List<Domain.Myfashion.Domain.AddFacebookPage>(); FacebookClient fb = new FacebookClient(); string profileId = string.Empty; Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("client_id", client_id); parameters.Add("redirect_uri", redirect_uri); parameters.Add("client_secret", client_secret); parameters.Add("code", code); System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; JsonObject fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters); string accessToken = fbaccess_token["access_token"].ToString(); dynamic output = null; if (accessToken != null) { fb.AccessToken = accessToken; dynamic profile = fb.Get("v2.0/me"); output = fb.Get("v2.0/me/accounts"); foreach (var item in output["data"]) { try { Domain.Myfashion.Domain.AddFacebookPage objAddFacebookPage = new Domain.Myfashion.Domain.AddFacebookPage(); objAddFacebookPage.ProfilePageId = item["id"].ToString(); try { //dynamic post = fb.Get(item["id"] + "/likes?summary=1&limit=500"); dynamic postlike = fb.Get("v2.0/" + item["id"]); objAddFacebookPage.LikeCount = postlike["likes"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error(ex.Message); logger.Error(ex.StackTrace); } if (objAddFacebookPage.LikeCount == null) { objAddFacebookPage.LikeCount = "0"; } objAddFacebookPage.Name = item["name"].ToString(); objAddFacebookPage.AccessToken = item["access_token"].ToString(); try { objAddFacebookPage.Email = profile["email"].ToString(); } catch (Exception ex) { objAddFacebookPage.Email = null; Console.WriteLine(ex.StackTrace); logger.Error(ex.StackTrace); } lstAddFacebookPage.Add(objAddFacebookPage); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } } return new JavaScriptSerializer().Serialize(lstAddFacebookPage); }