Guest User

Untitled

a guest
Mar 11th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 79.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using FB.App_UserControl;
  6. using FB.App_Common;
  7. using System.Collections.Specialized;
  8. using System.Data.SQLite;
  9. using FB.App_Model;
  10. using System.Web.Script.Serialization;
  11. using OpenPop.Pop3;
  12. using System.Text.RegularExpressions;
  13. using System.Web;
  14. using System.Drawing;
  15. using System.IO;
  16. using System.Net;
  17. using System.Collections;
  18. using System.Globalization;
  19. using System.Diagnostics;
  20.  
  21. namespace FB.App_Controller
  22. {
  23.     public class FaceBookController
  24.     {
  25.         public bool LoginMobile(FaceBook model, WebClientEx client)
  26.         {
  27.             try
  28.             {
  29.                 if (client == null)
  30.                 {
  31.                     client = new WebClientEx();
  32.                     client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  33.                     client.DoGet("https://developers.facebook.com/resources/dialog_descriptions_android.json");
  34.                 }
  35.                 NameValueCollection param = new NameValueCollection();
  36.                 param.Add("api_key", AppSettings.api_key);
  37.                 param.Add("client_country_code", "VN");
  38.                 param.Add("credentials_type", "password");
  39.                 param.Add("email", model.Login);
  40.                 param.Add("error_detail_type", "button_with_disabled");
  41.                 param.Add("fb_api_caller_class", "com.facebook.auth.protocol.AuthenticateMethod");
  42.                 param.Add("fb_api_req_friendly_name", "authenticate");
  43.                 param.Add("format", "json");
  44.                 param.Add("generate_machine_id", "1");
  45.                 param.Add("generate_session_cookies", "1");
  46.                 param.Add("locale", "vi_VN");
  47.                 param.Add("method", "auth.login");
  48.                 param.Add("password", model.Pass);
  49.                 string sig = Utilities.getSignFB(param, AppSettings.api_secret);
  50.                 param.Add("sig", sig);
  51.  
  52.                 client.DoPost(param, "https://b-api.facebook.com/method/auth.login");
  53.                 if (!string.IsNullOrEmpty(client.ResponseText)
  54.                     && client.ResponseText.Contains("session_key")
  55.                     && client.ResponseText.Contains("access_token"))
  56.                 {
  57.                     model.MBLoginText = client.ResponseText;
  58.                     model.MBCookie = Utilities.ConvertObjectToBlob(client.CookieContainer);
  59.  
  60.                     Dictionary<string, object> rs = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(client.ResponseText);
  61.                     if (rs.ContainsKey("uid"))
  62.                     {
  63.                         model.FBID = rs["uid"].ToString();
  64.                         return true;
  65.                     }
  66.                 }
  67.             }
  68.             catch (Exception ex)
  69.             {
  70.                 throw ex;
  71.             }
  72.             return false;
  73.         }
  74.  
  75.         public bool LoginMobile(FaceBook model)
  76.         {
  77.             return this.LoginMobile(model, null);
  78.         }
  79.  
  80.         public bool checkFaceBook(FaceBook model)
  81.         {
  82.             FBExtraData exData = GetExtraData(model);
  83.             WebClientEx client = new WebClientEx();
  84.             client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  85.             Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  86.             ArrayList listPost = new ArrayList();
  87.             client.Authorization = dicData["access_token"].ToString();
  88.             NameValueCollection param = new NameValueCollection();
  89.             string hash_id = Utilities.GetMd5Hash(DateTime.Now.Ticks.ToString());
  90.             hash_id = hash_id.Substring(0, 8) + "-" + hash_id.Substring(8, 4) + "-" + hash_id.Substring(12, 4) + "-" + hash_id.Substring(16, 4) + "-" + hash_id.Substring(20, 12);
  91.             #region - Check live -
  92.             {
  93.                 WebClientEx clientAPI = new WebClientEx();
  94.                 clientAPI.DoGet("https://graph.facebook.com/v2.1/me/?access_token=" + client.Authorization + "&fields=birthday&format=json&method=get&pretty=0&suppress_http_code=1");
  95.                 if (clientAPI.Error == null && clientAPI.ResponseText.Contains("birthday"))
  96.                 {
  97.                     //Live
  98.                     if (!exData.BirthDay.HasValue)
  99.                     {
  100.                         try
  101.                         {
  102.  
  103.                             exData.BirthDay = DateTime.Parse(Regex.Match(clientAPI.ResponseText, "birthday\":\"(?<val>[^\"]+)").Groups["val"].Value.Replace("\\/", "-")
  104.                                 , new DateTimeFormatInfo { FullDateTimePattern = "dd-MM-yyyy" }, DateTimeStyles.None);
  105.                         }
  106.                         catch { }
  107.                     }
  108.                 }
  109.                 else if (!string.IsNullOrEmpty(clientAPI.ResponseText) && clientAPI.ResponseText.Contains("\"error\""))
  110.                 {
  111.                     //model.FBPackageID = 1;
  112.                     //Global.DBContext.SaveChanges();
  113.                     return false;
  114.                 }
  115.                 else
  116.                 {
  117.                     return true;
  118.                 }
  119.             }
  120.             //Like(model, "bichlien1234");
  121.             //Like(model, "352321118281980");
  122.             //Like(model, "150884418415392");
  123.             return true;
  124.             #endregion
  125.             #region - Get New Feed -
  126.             {
  127.                 param = new NameValueCollection();
  128.                 param.Add("batch", "[{'method':'POST','body':'query_id=10153084471926729&method=get&query_params=%7B%22action_location%22%3A%22feed%22%7D&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=NewsFeedQueryDepth2','name':'first-fetch','omit_response_on_success':false,'relative_url':'graphql'}]".Replace("'", "\""));
  129.                 param.Add("fb_api_caller_class", "com.facebook.feed.server.NewsFeedServiceImplementation");
  130.                 param.Add("flush", "1");
  131.                 client.DoPost(param, "https://graph.facebook.com/?include_headers=false&decode_body_json=false&streamable_json_response=true&locale=vi_VN&client_country_code=VN");
  132.                 if (client.Error == null && !string.IsNullOrEmpty(client.ResponseText))
  133.                 {
  134.                     try
  135.                     {
  136.                         dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(client.ResponseText);
  137.                         if (dicData.ContainsKey("first-fetch") && dicData["first-fetch"] is ArrayList)
  138.                         {
  139.                             foreach (Dictionary<string, object> dicFeed in dicData["first-fetch"] as ArrayList)
  140.                             {
  141.                                 if (dicFeed.ContainsKey("body"))
  142.                                 {
  143.                                     listPost = (((dicFeed["body"] as Dictionary<string, object>)["viewer"] as Dictionary<string, object>)["news_feed"] as Dictionary<string, object>)["edges"] as ArrayList;
  144.                                 }
  145.                             }
  146.                         }
  147.                     }
  148.                     catch { }
  149.                 }
  150.             }
  151.             #endregion
  152.             #region - Post Status -
  153.             System.Threading.Thread.Sleep(23);
  154.             if (!exData.LastUpdateStatus.HasValue || exData.LastUpdateStatus.Value.Date.AddDays(new Random().Next(0, 2)) < DateTime.Today)
  155.             {
  156.                 if (PostStatus(model))
  157.                 {
  158.                     exData.LastUpdateStatus = DateTime.Now;
  159.                 }
  160.             }
  161.             #endregion
  162.             #region - Upload photo -
  163.             System.Threading.Thread.Sleep(23);
  164.             if (!exData.LastUpLoadPhoto.HasValue || exData.LastUpLoadPhoto.Value.Date.AddDays(new Random().Next(0, 4)) < DateTime.Today)
  165.             {
  166.                 if (Global.LisCoverPhotoLink.Count > 0)
  167.                 {
  168.                     UploadPhoto(client.Authorization, Global.LisCoverPhotoLink[0]);
  169.                     Global.LisCoverPhotoLink.RemoveAt(0);
  170.                     exData.LastUpLoadPhoto = DateTime.Now;
  171.                 }
  172.             }
  173.             #endregion
  174.             #region - Update Profile Photo -
  175.             System.Threading.Thread.Sleep(23);
  176.             if (!exData.LastUpdateProfilePhoto.HasValue || exData.LastUpdateProfilePhoto.Value.Date.AddDays(new Random().Next(5, 10)) < DateTime.Today)
  177.             {
  178.                 if (Global.ListProfilePhotoLink.Count > 0)
  179.                 {
  180.                     string id = UploadPhoto(client.Authorization, Global.ListProfilePhotoLink[0]);
  181.                     Global.ListProfilePhotoLink.RemoveAt(0);
  182.                     if (!string.IsNullOrEmpty(id))
  183.                     {
  184.                         param = new NameValueCollection();
  185.                         param.Add("batch", "[{\"method\":\"POST\",\"body\":\"qn=" + hash_id
  186.                      + "&time_since_original_post=3&scaled_crop_rect=%7B%22y%22%3A0%2C%22height%22%3A1%2C%22width%22%3A1%2C%22x%22%3A0%7D&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=publish-photo\",\"name\":\"publish\",\"omit_response_on_success\":false,"
  187.                      + "\"relative_url\":\"" + model.FBID + "/picture/" + id + "\"}]");
  188.                         param.Add("fb_api_caller_class", "com.facebook.photos.upload.protocol.PhotoPublisher");
  189.                         client.DoPost(param, "https://graph.facebook.com/?include_headers=false&locale=vi_VN&client_country_code=VN");
  190.                         exData.LastUpdateProfilePhoto = DateTime.Now;
  191.                     }
  192.                 }
  193.             }
  194.             #endregion
  195.             #region - Update Cover Photo -
  196.             System.Threading.Thread.Sleep(23);
  197.             if (!exData.LastUpdateCoverPhoto.HasValue || exData.LastUpdateCoverPhoto.Value.Date.AddDays(new Random().Next(5, 10)) < DateTime.Today)
  198.             {
  199.                 if (Global.LisCoverPhotoLink.Count > 0)
  200.                 {
  201.                     string id = UploadPhoto(client.Authorization, Global.LisCoverPhotoLink[Global.LisCoverPhotoLink.Count - 1]);
  202.                     Global.LisCoverPhotoLink.RemoveAt(Global.LisCoverPhotoLink.Count - 1);
  203.                     if (!string.IsNullOrEmpty(id))
  204.                     {
  205.                         param = new NameValueCollection();
  206.                         param.Add("batch", "[{\"method\":\"POST\",\"body\":\"qn=" + hash_id
  207.                          + "&time_since_original_post=12&photo=" + id + "&focus_y=0&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=publish-photo\",\"name\":\"publish\",\"omit_response_on_success\":false,"
  208.                          + "\"relative_url\":\"" + model.FBID + "/cover\"}]");
  209.                         param.Add("fb_api_caller_class", "com.facebook.photos.upload.protocol.PhotoPublisher");
  210.                         client.DoPost(param, "https://graph.facebook.com/?include_headers=false&locale=vi_VN&client_country_code=VN");
  211.                         exData.LastUpdateCoverPhoto = DateTime.Now;
  212.                     }
  213.                 }
  214.             }
  215.             #endregion
  216.             #region - Like -
  217.             if (listPost.Count > 0)
  218.             {
  219.                 System.Threading.Thread.Sleep(23);
  220.                 int iRD = new Random().Next(0, 4);
  221.                 for (int iIndex = 0; iIndex < iRD; iIndex++)
  222.                 {
  223.                     if (listPost.Count > iIndex)
  224.                     {
  225.                         string strPostID = string.Empty;
  226.                         try
  227.                         {
  228.                             strPostID = (((listPost[iIndex] as Dictionary<string, object>)["node"] as Dictionary<string, object>)["feedback"] as Dictionary<string, object>)["legacy_api_post_id"].ToString();
  229.                         }
  230.                         catch { }
  231.                         if (!string.IsNullOrEmpty(strPostID))
  232.                         {
  233.                             Like(model, strPostID);
  234.                             //System.Threading.Thread.Sleep(1000);
  235.                         }
  236.                     }
  237.                 }
  238.             }
  239.             #endregion
  240.             #region - Comment -
  241.             if (listPost.Count > 0)
  242.             {
  243.                 System.Threading.Thread.Sleep(23);
  244.                 int iRD = new Random().Next(0, 4);
  245.                 for (int iIndex = 0; iIndex < iRD; iIndex++)
  246.                 {
  247.                     if (listPost.Count > iIndex)
  248.                     {
  249.                         string strPostID = string.Empty;
  250.                         try
  251.                         {
  252.                             strPostID = (((listPost[iIndex] as Dictionary<string, object>)["node"] as Dictionary<string, object>)["feedback"] as Dictionary<string, object>)["legacy_api_post_id"].ToString();
  253.                         }
  254.                         catch { }
  255.                         if (!string.IsNullOrEmpty(strPostID))
  256.                         {
  257.                             Comment(model, strPostID);
  258.                             //System.Threading.Thread.Sleep(1000);
  259.                         }
  260.                     }
  261.                 }
  262.             }
  263.             #endregion
  264.             #region - Make Friend -
  265.             {
  266.                 System.Threading.Thread.Sleep(23);
  267.                 int iRD = new Random().Next(0, 3);
  268.                 //Select in Package
  269.                 List<FaceBook> listFB = getFaceBookNotFriend(model, true, iRD);
  270.                 while (listFB.Count > 0 && iRD > 0)
  271.                 {
  272.                     if (SendFriendRequest(model, listFB[0]) &&
  273.                      AcceptFriendRequest(listFB[0], model))
  274.                     {
  275.                         Global.DBContext.FBFriend.Add(new FBFriend { FBID1 = model.ID, FBID2 = listFB[0].ID });
  276.                         Global.DBContext.SaveChanges();
  277.                     }
  278.                     listFB.RemoveAt(0);
  279.                     iRD--;
  280.                 }
  281.                 //Select in Package
  282.                 listFB = getFaceBookNotFriend(model, false, iRD);
  283.                 while (listFB.Count > 0 && iRD > 0)
  284.                 {
  285.                     if (SendFriendRequest(model, listFB[0]) &&
  286.                      AcceptFriendRequest(listFB[0], model))
  287.                     {
  288.                         Global.DBContext.FBFriend.Add(new FBFriend { FBID1 = model.ID, FBID2 = listFB[0].ID });
  289.                         Global.DBContext.SaveChanges();
  290.                     }
  291.                     listFB.RemoveAt(0);
  292.                     iRD--;
  293.                 }
  294.             }
  295.             #endregion
  296.             SetExtraData(model, exData);
  297.             Global.DBContext.SaveChanges();
  298.             return true;
  299.         }
  300.  
  301.         private List<FaceBook> getFaceBookNotFriend(FaceBook model, bool bInpackage, int iNo)
  302.         {
  303.             if (bInpackage)
  304.             {
  305.                 return (from fb in Global.DBContext.FaceBook
  306.                         where fb.ID != model.ID
  307.                         && fb.FBPackageID == model.FBPackageID
  308.                         && !(from o in Global.DBContext.FBFriend
  309.                              where o.FBID2 == model.ID
  310.                              select o.FBID1)
  311.                                .Contains(fb.ID)
  312.                        && !(from o in Global.DBContext.FBFriend
  313.                             where o.FBID1 == model.ID
  314.                             select o.FBID2)
  315.                        .Contains(fb.ID)
  316.                         select fb).ToList();
  317.             }
  318.             else
  319.             {
  320.                 return (from fb in Global.DBContext.FaceBook
  321.                         where fb.ID != model.ID
  322.                         && !(from o in Global.DBContext.FBFriend
  323.                              where o.FBID2 == model.ID
  324.                              select o.FBID1)
  325.                                .Contains(fb.ID)
  326.                        && !(from o in Global.DBContext.FBFriend
  327.                             where o.FBID1 == model.ID
  328.                             select o.FBID2)
  329.                        .Contains(fb.ID)
  330.                         select fb).Take(iNo).ToList();
  331.             }
  332.         }
  333.  
  334.         public bool SendFriendRequest(FaceBook model1, FaceBook model2)
  335.         {
  336.             try
  337.             {
  338.                 WebClientEx client = new WebClientEx();
  339.                 client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  340.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model1.MBLoginText);
  341.                 client.Authorization = dicData["access_token"].ToString();
  342.  
  343.                 NameValueCollection param = new NameValueCollection();
  344.                 param.Add("uid", model2.FBID);
  345.                 param.Add("hf", "profile_button");
  346.                 param.Add("ref", "pb_likes");
  347.                 param.Add("format", "json");
  348.                 param.Add("locale", "vi_VN");
  349.                 param.Add("client_country_code", "VN");
  350.                 param.Add("fb_api_req_friendly_name", "sendFriendRequest");
  351.                 param.Add("fb_api_caller_class", "com.facebook.friends.protocol.SendFriendRequestMethod");
  352.  
  353.                 client.DoPost(param, "https://graph.facebook.com/me/friends");
  354.                 if (!string.IsNullOrEmpty(client.ResponseText) && (client.ResponseText == "true"
  355.                     || client.ResponseText.Contains("There is already a pending friend request to this user")))
  356.                 {
  357.                     return true;
  358.                 }
  359.             }
  360.             catch (Exception ex)
  361.             {
  362.                 throw ex;
  363.             }
  364.             return false;
  365.         }
  366.  
  367.         public bool AcceptFriendRequest(FaceBook model1, FaceBook model2)
  368.         {
  369.             try
  370.             {
  371.                 WebClientEx client = new WebClientEx();
  372.                 client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  373.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model1.MBLoginText);
  374.                 client.Authorization = dicData["access_token"].ToString();
  375.  
  376.                 NameValueCollection param = new NameValueCollection();
  377.                 param.Add("uid", model2.FBID);
  378.                 param.Add("confirm", "1");
  379.                 param.Add("ref", "m_jewel");
  380.                 param.Add("format", "json");
  381.                 param.Add("locale", "vi_VN");
  382.                 param.Add("client_country_code", "VN");
  383.                 param.Add("fb_api_req_friendly_name", "respondToFriendRequest");
  384.                 param.Add("method", "facebook.friends.confirm");
  385.                 param.Add("fb_api_caller_class", "com.facebook.friends.protocol.RespondToFriendRequestMethod");
  386.  
  387.                 client.DoPost(param, "https://api.facebook.com/method/facebook.friends.confirm");
  388.                 if (!string.IsNullOrEmpty(client.ResponseText) && client.ResponseText == "true")
  389.                 {
  390.                     return true;
  391.                 }
  392.             }
  393.             catch (Exception ex)
  394.             {
  395.                 throw ex;
  396.             }
  397.             return false;
  398.         }
  399.  
  400.         public string GetFaceBookLoginURL(FaceBook model, string strDestURl)
  401.         {
  402.             string strURl = string.Empty;
  403.             try
  404.             {
  405.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  406.                 string secret = dicData["secret"].ToString();
  407.                 string session_key = dicData["session_key"].ToString();
  408.  
  409.                 NameValueCollection param = new NameValueCollection();
  410.                 param.Add("api_key", AppSettings.api_key);
  411.                 param.Add("session_key", session_key);
  412.                 param.Add("t", Utilities.GetCurrentSecond());
  413.                 param.Add("uid", model.FBID);
  414.                 param.Add("url", strDestURl);
  415.  
  416.                 string sig = Utilities.getSignFB(param, secret);
  417.                 //param.Add("sig", sig);
  418.  
  419.                 strURl = "https://m.facebook.com/auth.php?api_key="
  420.                     + AppSettings.api_key
  421.                     + "&session_key=" + session_key
  422.                     + "&sig=" + sig
  423.                     + "&t=" + param["t"]
  424.                     + "&uid=" + model.FBID
  425.                     + "&url=" + param["url"];
  426.             }
  427.             catch (Exception ex)
  428.             {
  429.                 throw ex;
  430.             }
  431.             return strURl;
  432.         }
  433.  
  434.         public void FeedAccessToken(FaceBook model)
  435.         {
  436.             try
  437.             {
  438.                 WebClientEx client = new WebClientEx();
  439.                 client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  440.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  441.                 client.Authorization = dicData["access_token"].ToString();
  442.                 NameValueCollection param = new NameValueCollection();
  443.                 param.Add("batch", "[{'method':'GET','name':'prefetchAccessToken','omit_response_on_success':false,'relative_url':'fql?format=json&q=%7B%22token_query%22%3A%22SELECT+page_id%2C+name%2C+access_token+FROM+page+WHERE+page_id+IN+%28SELECT+page_id+FROM+%23page_query%29%22%2C%22page_query%22%3A%22SELECT+page_id+FROM+page_admin+WHERE+uid+%3D+me%28%29+AND+type+%21%3D+%27APPLICATION%27+ORDER+BY+last_used_time+DESC%22%7D&locale=en_US&client_country_code=VN&fb_api_req_friendly_name=page_access_token'}]".Replace("'", "\""));
  444.                 param.Add("fb_api_caller_class", "com.facebook.feed.server.NewsFeedServiceImplementation");
  445.                 param.Add("flush", "1");
  446.                 client.DoPost(param, "https://graph.facebook.com/?include_headers=false&decode_body_json=false&streamable_json_response=true&locale=vi_VN&client_country_code=VN");
  447.                 if (client.Error == null && !string.IsNullOrEmpty(client.ResponseText))
  448.                 {
  449.                     dicData = new JavaScriptSerializer { MaxJsonLength = int.MaxValue }.Deserialize<Dictionary<string, object>>(client.ResponseText);
  450.                     foreach (Dictionary<string, object> pagefeed in ((((((dicData["prefetchAccessToken"] as ArrayList)[1] as Dictionary<string, object>)["body"] as Dictionary<string, object>)["data"] as ArrayList)[1] as Dictionary<string, object>)["fql_result_set"] as ArrayList))
  451.                     {
  452.                         Page page = getFBByID(pagefeed["page_id"].ToString());
  453.                         if (page == null)
  454.                         {
  455.                             page = new Page();
  456.                             Global.DBContext.Page.Add(page);
  457.                         }
  458.                         page.AccessToken = pagefeed["access_token"].ToString();
  459.                         page.FaceBookID = model.ID;
  460.                         page.PageID = pagefeed["page_id"].ToString();
  461.                         page.PageName = pagefeed["name"].ToString();
  462.                     }
  463.                     Global.DBContext.SaveChanges();
  464.                 }
  465.             }
  466.             catch (Exception ex)
  467.             {
  468.  
  469.             }
  470.         }
  471.  
  472.         public void RenameToUS(FaceBook model)
  473.         {
  474.             try
  475.             {
  476.                 FBExtraData extraData = GetExtraData(model);
  477.                 if (extraData != null && extraData.ProfileUS.HasValue && extraData.ProfileUS.Value) return;
  478.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  479.                 if (dicData != null && dicData.ContainsKey("session_cookies"))
  480.                 {
  481.                     WebClientEx client = new WebClientEx();
  482.                     client.CookieContainer = new CookieContainer();
  483.                     foreach (Dictionary<string, object> dicCookie in dicData["session_cookies"] as ArrayList)
  484.                     {
  485.                         client.CookieContainer.Add(new Cookie(dicCookie["name"].ToString(), dicCookie["value"].ToString()
  486.                             , dicCookie["path"].ToString(), dicCookie["domain"].ToString()));
  487.                     }
  488.                     foreach (Page page in model.Pages)
  489.                     {
  490.                         client.DoGet("https://m.facebook.com/pages/edit/info/" + page.PageID);
  491.                         NameValueCollection param = new NameValueCollection();
  492.                         string fb_dtsg = Regex.Match(client.ResponseText, "\"token\":\"(?<val>[^\"]+)").Groups["val"].Value;
  493.                         if (!string.IsNullOrEmpty(fb_dtsg))
  494.                         {
  495.                             page.PageName = Utilities.GetMaleName(true);
  496.                             param.Add("fb_dtsg", fb_dtsg);
  497.                             param.Add("charset_test", "€,´,€,´,水,Д,Є");
  498.                             param.Add(page.PageID + ":name", page.PageName);
  499.                             param.Add("m_sess", "");
  500.                             param.Add("__dyn", "");
  501.                             param.Add("__req", "1");
  502.                             param.Add("__ajax__", "true");
  503.                             param.Add("__user", model.FBID);
  504.                             client.DoPost(param, "https://m.facebook.com/a/pages/edit/info/" + page.PageID);
  505.                         }
  506.                     }
  507.                     extraData.ProfileUS = true;
  508.                     SetExtraData(model, extraData);
  509.                 }
  510.             }
  511.             catch (Exception ex)
  512.             {
  513.  
  514.             }
  515.         }
  516.  
  517.         public void UpdatePhotoAndCover(Page model)
  518.         {
  519.             PageData pageData = new JavaScriptSerializer { MaxJsonLength = int.MaxValue }.Deserialize<PageData>(model.PageData == null ? "" : model.PageData);
  520.             if (pageData == null) pageData = new PageData();
  521.             if (pageData.LUCP.HasValue) return;
  522.             WebClientEx client = new WebClientEx();
  523.             client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  524.             client.Authorization = model.AccessToken;
  525.             NameValueCollection param = new NameValueCollection();
  526.             #region - Upload profile picture -
  527.  
  528.             if (Global.ListProfilePhotoLink.Count > 0)
  529.             {
  530.                 string id = UploadPhoto(model.AccessToken, Global.ListProfilePhotoLink[0]);
  531.                 Global.ListProfilePhotoLink.RemoveAt(0);
  532.                 if (!string.IsNullOrEmpty(id))
  533.                 {
  534.                     param = new NameValueCollection();
  535.                     string hash_id = Utilities.GetMd5Hash(DateTime.Now.Ticks.ToString());
  536.                     hash_id = hash_id.Substring(0, 8) + "-" + hash_id.Substring(8, 4) + "-" + hash_id.Substring(12, 4) + "-" + hash_id.Substring(16, 4) + "-" + hash_id.Substring(20, 12);
  537.  
  538.                     param.Add("batch", "[{\"method\":\"POST\",\"body\":\"qn=" + hash_id
  539.                  + "&scaled_crop_rect=%7B%22y%22%3A0%2C%22height%22%3A1%2C%22width%22%3A1%2C%22x%22%3A0%7D&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=publish-photo\",\"name\":\"publish\",\"omit_response_on_success\":false,"
  540.                  + "\"relative_url\":\"" + model.PageID + "/picture/" + id + "\"}]");
  541.                     param.Add("fb_api_caller_class", "com.facebook.photos.upload.protocol.PhotoPublisher");
  542.                     client.DoPost(param, "https://graph.facebook.com/?include_headers=false&locale=vi_VN&client_country_code=VN");
  543.                 }
  544.             }
  545.             #endregion
  546.  
  547.             #region - update cover photo -
  548.             if (Global.LisCoverPhotoLink.Count > 0)
  549.             {
  550.                 string id = UploadPhoto(client.Authorization, Global.LisCoverPhotoLink[Global.LisCoverPhotoLink.Count - 1]);
  551.                 Global.LisCoverPhotoLink.RemoveAt(Global.LisCoverPhotoLink.Count - 1);
  552.  
  553.                 if (!string.IsNullOrEmpty(id))
  554.                 {
  555.                     param = new NameValueCollection();
  556.                     string hash_id = Utilities.GetMd5Hash(DateTime.Now.Ticks.ToString());
  557.                     hash_id = hash_id.Substring(0, 8) + "-" + hash_id.Substring(8, 4) + "-" + hash_id.Substring(12, 4) + "-" + hash_id.Substring(16, 4) + "-" + hash_id.Substring(20, 12);
  558.  
  559.                     param.Add("batch", "[{\"method\":\"POST\",\"body\":\"qn=" + hash_id
  560.                      + "&photo=" + id + "&focus_y=0&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=publish-photo\",\"name\":\"publish\",\"omit_response_on_success\":false,"
  561.                      + "\"relative_url\":\"" + model.PageID + "/cover\"}]");
  562.                     param.Add("fb_api_caller_class", "com.facebook.photos.upload.protocol.PhotoPublisher");
  563.                     client.DoPost(param, "https://graph.facebook.com/?include_headers=false&locale=vi_VN&client_country_code=VN");
  564.                 }
  565.             }
  566.             #endregion
  567.  
  568.             pageData.LUCP = DateTime.Now;
  569.             pageData.LUPP = DateTime.Now;
  570.             model.PageData = new JavaScriptSerializer { MaxJsonLength = int.MaxValue }.Serialize(pageData);
  571.         }
  572.  
  573.         public void UpdatePhotoAndCover(FaceBook model)
  574.         {
  575.             foreach (Page page in model.Pages)
  576.             {
  577.                 UpdatePhotoAndCover(page);
  578.             }
  579.             if (Global.DBContext.ChangeTracker.HasChanges())
  580.             {
  581.                 Global.DBContext.SaveChanges();
  582.             }
  583.         }
  584.  
  585.         private Page getFBByID(string PageID)
  586.         {
  587.             return Global.DBContext.Page.Where(page => page.PageID == PageID).FirstOrDefault();
  588.         }
  589.  
  590.         public void CreateNewPage(FaceBook model)
  591.         {
  592.             FBExtraData extraData = GetExtraData(model);
  593.             if (extraData.BlockCreatePage.HasValue && extraData.BlockCreatePage.Value) return;
  594.             if (model.Pages.Count >= 300) return;
  595.             int iCount = 0;
  596.             while (iCount < 500)
  597.             {
  598.  
  599.                 WebClientEx client = new WebClientEx();
  600.                 client.DoGet(GetFaceBookLoginURL(model, "https://m.facebook.com/pages/create"));
  601.                 NameValueCollection param = new NameValueCollection();
  602.                 List<string> listSub = new List<string>() { "1103", "1601", "1600", "1301", "1609", "1606", "1802", "1610", "1614", "1615", "1611", "1617", "1113", "1701", "1604", "1114", "1202", "1605", "2632", "1616", "1700", "1108", "1602", "1613", "1109" };
  603.  
  604.                 string fb_dtsg = Regex.Match(client.ResponseText, "\"token\":\"(?<val>[^\"]+)").Groups["val"].Value;
  605.  
  606.                 Page page = new Page();
  607.                 page.FaceBookID = model.ID;
  608.                 page.PageName = Utilities.GetMaleName(false);
  609.  
  610.                 param.Add("fb_dtsg", fb_dtsg);
  611.                 param.Add("charset_test", "€,´,€,´,水,Д,Є");
  612.                 param.Add("page_name", page.PageName);
  613.                 param.Add("super_category", "1007");
  614.                 param.Add("category", listSub[new Random().Next(0, listSub.Count - 1)]);
  615.                 param.Add("m_sess", "");
  616.                 param.Add("__dyn", "");
  617.                 param.Add("__req", "2");
  618.                 param.Add("__ajax__", "true");
  619.                 param.Add("__user", model.FBID);
  620.                 client.DoPost(param, "https://m.facebook.com/pages/create/add/");
  621.                 if (client.Error == null && !string.IsNullOrEmpty(client.ResponseText))
  622.                 {
  623.                     //if (client.ResponseText.Contains("Please slow down, or you could be blocked from using it")) return;
  624.                     string strpageID = Regex.Match(client.ResponseText, @"getting_started\.php\?id=(?<val>[0-9]+)").Groups["val"].Value;
  625.                     if (!string.IsNullOrEmpty(strpageID))
  626.                     {
  627.                         //return;
  628.                         //page.PageID = strpageID;
  629.                         //Global.DBContext.Page.Add(page);
  630.                         //int iBeginWait = 0;
  631.                         //while (Global.ContextBusy && iBeginWait < 10)
  632.                         //{
  633.                         //    System.Threading.Thread.Sleep(new Random().Next(200, 1000));
  634.                         //    iBeginWait++;
  635.                         //}
  636.                         //Global.ContextBusy = true;
  637.                         //Global.DBContext.SaveChanges();
  638.                         //Global.ContextBusy = false;
  639.                         //iCount++;
  640.                     }
  641.                     else if (client.ResponseText.Contains(@"khi s\u1eed d\u1ee5ng qu\u00e1 nhanh") || client.ResponseText.Contains(@"You\u2019ve been blocked from using it"))
  642.                     {
  643.                         extraData.BlockCreatePage = true;
  644.                         SetExtraData(model, extraData);
  645.                         return;
  646.                     }
  647.                     else
  648.                     {
  649.                         return;
  650.                     }
  651.                     //else return;
  652.                 }
  653.                 System.Threading.Thread.Sleep(5000);
  654.             }
  655.         }
  656.  
  657.         public FaceBook RegNewAccount()
  658.         {
  659.             Debug.WriteLine("-- Start INNER Reg --");
  660.             FaceBook model = null;
  661.             FBExtraData extraData = new FBExtraData();
  662.  
  663.             WebClientEx client = new WebClientEx();
  664.             client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  665.  
  666.             NameValueCollection param = new NameValueCollection();
  667.  
  668.             string hash_id = Utilities.GetMd5Hash(DateTime.Now.Ticks.ToString());
  669.             hash_id = hash_id.Substring(0, 8) + "-" + hash_id.Substring(8, 4) + "-" + hash_id.Substring(12, 4) + "-" + hash_id.Substring(16, 4) + "-" + hash_id.Substring(20, 12);
  670.             string sig = Utilities.getSignFB(param, AppSettings.api_secret);
  671.  
  672.             string strName = Utilities.GetMaleName(false);
  673.             param = new NameValueCollection();
  674.             param.Add("api_key", AppSettings.api_key);
  675.             param.Add("attempt_login", "true");
  676.             {
  677.                 System.Threading.Thread.Sleep(23);
  678.                 int iY = new Random().Next(1979, 1990);
  679.                 System.Threading.Thread.Sleep(23);
  680.                 int iM = new Random().Next(1, 12);
  681.                 System.Threading.Thread.Sleep(23);
  682.                 int iD = new Random(3).Next(1, 28);
  683.                 extraData.BirthDay = new DateTime(iY, iM, iD);
  684.             }
  685.             param.Add("birthday", extraData.BirthDay.Value.ToString("yyyy-MM-dd"));
  686.             param.Add("client_country_code", "VN");
  687.  
  688.             param.Add("fb_api_caller_class", "com.facebook.registration.protocol.RegisterAccountMethod");
  689.             param.Add("fb_api_req_friendly_name", "registerAccount");
  690.             param.Add("firstname", strName.Trim().Split(' ')[0]);
  691.             System.Threading.Thread.Sleep(34);
  692.             param.Add("format", "json");
  693.             param.Add("gender", "M");
  694.             param.Add("lastname", strName.Trim().Split(' ')[1]);
  695.             List<string> listEmail = new List<string>();
  696.             listEmail.Add("gmail.com");
  697.             listEmail.Add("hotmail.com");
  698.             listEmail.Add("yahoo.com");
  699.             listEmail.Add("live.com");
  700.             listEmail.Add("gmail.com");
  701.             listEmail.Add("rocket.com");
  702.             listEmail.Add("yahoo.com");
  703.             listEmail.Add("outlook.com");
  704.             listEmail.Add("live.com");
  705.             extraData.ComfirmedEmail = false;
  706.             param.Add("email", Utilities.ConvertToUnSign3(param["firstname"].Replace(" ", "").Trim() + param["lastname"].Replace(" ", "").Trim() + new Random().Next(10, 9999)).ToLower() + "@" + listEmail[new Random().Next(0, listEmail.Count - 1)]);
  707.             param.Add("locale", "vi_VN");
  708.             param.Add("method", "user.register"); string strPass = Utilities.ConvertToUnSign3(param["firstname"].Split(' ')[0] + new List<string> { "!", "@", "#", "$", "%", "^", "~", "&", "*", "(" }[new Random().Next(0, 10)] + param["lastname"].Split(' ')[0] + new Random().Next(10, 1000));
  709.             System.Threading.Thread.Sleep(19);
  710.             strPass += new List<string> { "!", "@", "#", "$", "%", "^", "~", "&", "*", "(" }[new Random().Next(0, 10)];
  711.             param.Add("password", strPass);
  712.             param.Add("reg_instance", hash_id);
  713.             param.Add("return_multiple_errors", "true");
  714.             sig = Utilities.getSignFB(param, AppSettings.api_secret);
  715.             param.Add("sig", sig);
  716.             client.SetCookieV2 = true;
  717.             //System.Threading.Thread.Sleep(5000);
  718.             client.DoPost(param, "https://b-api.facebook.com/method/user.register");
  719.             if (!string.IsNullOrEmpty(client.ResponseText) && client.Error == null)
  720.             {
  721.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(client.ResponseText);
  722.                 if (dicData.ContainsKey("session_info")
  723.                     && dicData.ContainsKey("account_type"))
  724.                 {
  725.                     model = new FaceBook();
  726.                     model.Login = param["email"];
  727.                     model.Pass = param["password"];
  728.                     model.MBLoginText = new JavaScriptSerializer().Serialize(dicData["session_info"]);
  729.                     model.FBID = (dicData["session_info"] as Dictionary<string, object>)["uid"].ToString();
  730.  
  731.                     if (LoginMobile(model, client))
  732.                     {
  733.                         client.SetCookieV2 = false;
  734.                         dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  735.                         client.Authorization = dicData["access_token"].ToString();
  736.  
  737.                         #region - Upload profile picture -
  738.                         if (Global.ListProfilePhotoLink.Count > 0)
  739.                         {
  740.                             string id = UploadPhoto(client.Authorization, Global.ListProfilePhotoLink[0]);
  741.                             Global.ListProfilePhotoLink.RemoveAt(0);
  742.                             if (!string.IsNullOrEmpty(id))
  743.                             {
  744.                                 param = new NameValueCollection();
  745.  
  746.                                 param.Add("batch", "[{\"method\":\"POST\",\"body\":\"qn=" + hash_id
  747.                              + "&scaled_crop_rect=%7B%22y%22%3A0%2C%22height%22%3A1%2C%22width%22%3A1%2C%22x%22%3A0%7D&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=publish-photo\",\"name\":\"publish\",\"omit_response_on_success\":false,"
  748.                              + "\"relative_url\":\"" + model.FBID + "/picture/" + id + "\"}]");
  749.                                 param.Add("fb_api_caller_class", "com.facebook.photos.upload.protocol.PhotoPublisher");
  750.                                 client.DoPost(param, "https://graph.facebook.com/?include_headers=false&locale=vi_VN&client_country_code=VN");
  751.                                 extraData.LastUpdateProfilePhoto = DateTime.Now;
  752.                             }
  753.                         }
  754.                         #endregion
  755.                         param = new NameValueCollection();
  756.                         param.Add("format", "JSON");
  757.                         param.Add("nux_id", "ANDROID_NEW_ACCOUNT_WIZARD");
  758.                         param.Add("step", "upload_profile_pic");
  759.                         param.Add("status", "COMPLETE");
  760.                         param.Add("extra_data", "{}");
  761.                         param.Add("locale", "vi_VN");
  762.                         param.Add("client_country_code", "VN");
  763.                         param.Add("method", "user.updateNuxStatus");
  764.                         param.Add("fb_api_req_friendly_name", "updateNuxStatus");
  765.                         param.Add("fb_api_caller_class", "com.facebook.nux.status.UpdateNuxStatusMethod");
  766.                         //System.Threading.Thread.Sleep(1000);
  767.                         client.DoPost(param, "https://api.facebook.com/method/user.updateNuxStatus");
  768.  
  769.                         #region - Update work and class info -
  770.                         param = new NameValueCollection();
  771.                         param.Add("work", ("[{'id':'" + Utilities.GetProfileInfo(4) + "','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android'}]").Replace("'", "\""));
  772.                         param.Add("education", ("[{'id':'" + Utilities.GetProfileInfo(3) + "','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android','type':'College'},{'id':'" + Utilities.GetProfileInfo(2) + "','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android','type':'High School'}]").Replace("'", "\""));
  773.                         //param.Add("location", "{'id':'108458769184495','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android'}".Replace("'", "\""));
  774.                         //param.Add("hometown", "{'id':'108458769184495','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android'}".Replace("'", "\""));
  775.                         param.Add("locale", "vi_VN");
  776.                         param.Add("client_country_code", "VN");
  777.                         param.Add("fb_api_req_friendly_name", "save_core_profile_info");
  778.                         client.DoPost(param, "https://graph.facebook.com/me");
  779.                         extraData.UpdatedProfileInfo = true;
  780.                         #endregion
  781.                         param = new NameValueCollection();
  782.                         param.Add("format", "JSON");
  783.                         param.Add("nux_id", "ANDROID_NEW_ACCOUNT_WIZARD");
  784.                         param.Add("step", "classmates_coworkers");
  785.                         param.Add("status", "COMPLETE");
  786.                         param.Add("extra_data", "{}");
  787.                         param.Add("locale", "vi_VN");
  788.                         param.Add("client_country_code", "VN");
  789.                         param.Add("method", "user.updateNuxStatus");
  790.                         param.Add("fb_api_req_friendly_name", "updateNuxStatus");
  791.                         param.Add("fb_api_caller_class", "com.facebook.nux.status.UpdateNuxStatusMethod");
  792.                         //System.Threading.Thread.Sleep(1000);
  793.                         client.DoPost(param, "https://api.facebook.com/method/user.updateNuxStatus");
  794.                         if (client.ResponseText.ToLower().Trim() != "true") return null;
  795.                         param = new NameValueCollection();
  796.                         param.Add("format", "JSON");
  797.                         param.Add("nux_id", "ANDROID_NEW_ACCOUNT_WIZARD");
  798.                         param.Add("step", "contact_importer");
  799.                         param.Add("status", "COMPLETE");
  800.                         param.Add("extra_data", "{}");
  801.                         param.Add("locale", "vi_VN");
  802.                         param.Add("client_country_code", "VN");
  803.                         param.Add("method", "user.updateNuxStatus");
  804.                         param.Add("fb_api_req_friendly_name", "updateNuxStatus");
  805.                         param.Add("fb_api_caller_class", "com.facebook.nux.status.UpdateNuxStatusMethod");
  806.                         //System.Threading.Thread.Sleep(1000);
  807.                         client.DoPost(param, "https://api.facebook.com/method/user.updateNuxStatus");
  808.                         //string strNewEmail = new Random().Next(1, 999) % 2 == 0 ? "@vuathuthanh.net" : "@tinphuong.com";
  809.                         string strNewEmail = "@tinphuong.com";
  810.                         strNewEmail = model.Login.Substring(0, model.Login.IndexOf("@")) + strNewEmail;
  811.                         param = new NameValueCollection();
  812.                         param.Add("add_contactpoint", strNewEmail);
  813.                         param.Add("add_contactpoint_type", "EMAIL");
  814.                         param.Add("format", "json");
  815.                         param.Add("locale", "vi_VN");
  816.                         param.Add("client_country_code", "VN");
  817.                         param.Add("fb_api_req_friendly_name", "editRegistrationContactpoint");
  818.                         param.Add("method", "user.editregistrationcontactpoint");
  819.                         param.Add("fb_api_caller_class", "com.facebook.confirmation.protocol.EditRegistrationContactpointMethod");
  820.  
  821.                         #region - confirm email -
  822.                         client.DoPost(param, "https://api.facebook.com/method/user.editregistrationcontactpoint");
  823.                         if (!string.IsNullOrEmpty(client.ResponseText) && client.ResponseText == "true")
  824.                         {
  825.                             string strCode = Utilities.GetConfirmCode(strNewEmail);
  826.                             if (!string.IsNullOrEmpty(strCode))
  827.                             {
  828.                                 param = new NameValueCollection();
  829.                                 param.Add("normalized_contactpoint", strNewEmail);
  830.                                 param.Add("contactpoint_type", "EMAIL");
  831.                                 param.Add("code", strCode);
  832.                                 param.Add("source", "ANDROID_DIALOG_API");
  833.                                 param.Add("format", "json");
  834.                                 param.Add("locale", "vi_VN");
  835.                                 param.Add("client_country_code", "VN");
  836.                                 param.Add("fb_api_req_friendly_name", "confirmContactpoint");
  837.                                 param.Add("method", "user.confirmcontactpoint");
  838.                                 param.Add("fb_api_caller_class", "com.facebook.confirmation.protocol.ConfirmContactpointMethod");
  839.                                 client.DoPost(param, "https://api.facebook.com/method/user.confirmcontactpoint");
  840.                                 model.Login = strNewEmail;
  841.                                 extraData.ComfirmedEmail = true;
  842.                             }
  843.                         }
  844.                         #endregion
  845.  
  846.                         #region - update cover photo -
  847.                         if (Global.LisCoverPhotoLink.Count > 0)
  848.                         {
  849.                             string id = UploadPhoto(client.Authorization, Global.LisCoverPhotoLink[Global.LisCoverPhotoLink.Count - 1]);
  850.                             Global.LisCoverPhotoLink.RemoveAt(Global.LisCoverPhotoLink.Count - 1);
  851.  
  852.                             if (!string.IsNullOrEmpty(id))
  853.                             {
  854.                                 param = new NameValueCollection();
  855.                                 param.Add("batch", "[{\"method\":\"POST\",\"body\":\"qn=" + hash_id
  856.                                  + "&photo=" + id + "&focus_y=0&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=publish-photo\",\"name\":\"publish\",\"omit_response_on_success\":false,"
  857.                                  + "\"relative_url\":\"" + model.FBID + "/cover\"}]");
  858.                                 param.Add("fb_api_caller_class", "com.facebook.photos.upload.protocol.PhotoPublisher");
  859.                                 client.DoPost(param, "https://graph.facebook.com/?include_headers=false&locale=vi_VN&client_country_code=VN");
  860.                                 extraData.LastUpdateCoverPhoto = DateTime.Now;
  861.                             }
  862.                         }
  863.                         #endregion
  864.                         //Like(model, "639987956113732");
  865.                         Debug.WriteLine("-- SetExtraData --");
  866.                         SetExtraData(model, extraData);
  867.                         Debug.WriteLine("-- End INNER Reg --");
  868.                         return model;
  869.                     }
  870.                 }
  871.             }
  872.             return null;
  873.         }
  874.  
  875.         public FaceBook CheckAccount(FaceBook model)
  876.         {
  877.             if (LoginMobile(model))
  878.             {
  879.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  880.                 if (dicData != null && dicData.ContainsKey("session_cookies"))
  881.                 {
  882.                     WebClientEx client = new WebClientEx();
  883.                     client.CookieContainer = new CookieContainer();
  884.                     foreach (Dictionary<string, object> dicCookie in dicData["session_cookies"] as ArrayList)
  885.                     {
  886.                         client.CookieContainer.Add(new Cookie(dicCookie["name"].ToString(), dicCookie["value"].ToString()
  887.                             , dicCookie["path"].ToString(), dicCookie["domain"].ToString()));
  888.                     }
  889.                     client.DoGet("https://www.facebook.com/settings");
  890.                     NameValueCollection param = new NameValueCollection();
  891.                     string USER_ID = Utilities.GetRegexString(client.ResponseText, "USER_ID", 2);
  892.                     #region - Change pass -
  893.                     System.Threading.Thread.Sleep(1000);
  894.                     client.DoGet("https://www.facebook.com/ajax/settings/account/password.php?__user=" + USER_ID + "&__a=1&__req=v");
  895.  
  896.                     param = new NameValueCollection();
  897.                     param.Add("fb_dtsg", Utilities.GetRegexString(client.ResponseText, "token", 2));
  898.                     param.Add("password_strength", "2");
  899.                     param.Add("password_old", model.Pass);
  900.                     param.Add("password_new", USER_ID);
  901.                     param.Add("password_confirm", USER_ID);
  902.                     param.Add("__user", USER_ID);
  903.                     param.Add("__a", "1");
  904.                     System.Threading.Thread.Sleep(1000);
  905.                     client.DoPost(param, "https://www.facebook.com/ajax/settings/account/password.php");
  906.  
  907.                     model.Login = USER_ID;
  908.                     model.Pass = USER_ID;
  909.                     #endregion
  910.  
  911.                     #region - Change Email -
  912.                     System.Threading.Thread.Sleep(1000);
  913.                     client.DoGet("https://www.facebook.com/ajax/settings/account/email.php?__user=" + USER_ID + "&__a=1&__req=v");
  914.                     string primary_email = WebUtility.HtmlDecode(Utilities.GetRegexString(client.ResponseText, "primary_email", 1));
  915.                     string fb_dtsg = Utilities.GetRegexString(client.ResponseText, "token", 2);
  916.                     param = new NameValueCollection();
  917.                     param.Add("fb_dtsg", fb_dtsg);
  918.                     param.Add("primary_email", primary_email);
  919.                     param.Add("new_email", USER_ID + "@tinphuong.com");
  920.                     param.Add("__user", USER_ID);
  921.                     param.Add("__a", "1");
  922.                     System.Threading.Thread.Sleep(1000);
  923.                     client.DoPost(param, "https://www.facebook.com/ajax/settings/account/email.php");
  924.                     string strCode = Utilities.GetConfirmCode(param["new_email"]);
  925.                     client.DoGet("https://m.facebook.com/entercode.php");
  926.  
  927.                     param = new NameValueCollection();
  928.                     param.Add("fb_dtsg", Utilities.GetRegexString(client.ResponseText, "fb_dtsg", 1));
  929.                     param.Add("charset_test", "€,´,€,´,水,Д,Є");
  930.                     param.Add("code", strCode);
  931.                     param.Add("submit", "Chấp nhận");
  932.                     param.Add("__ajax__", "true");
  933.                     param.Add("__user", USER_ID);
  934.                     System.Threading.Thread.Sleep(1000);
  935.                     client.DoPost(param, "https://m.facebook.com/entercode.php?step=validate");
  936.  
  937.                     param = new NameValueCollection();
  938.                     param.Add("fb_dtsg", fb_dtsg);
  939.                     param.Add("primary_email", USER_ID + "@tinphuong.com");
  940.                     //param.Add("remove_emails[0]", primary_email);
  941.                     param.Add("new_email", "");
  942.                     param.Add("__user", USER_ID);
  943.                     param.Add("__a", "1");
  944.                     System.Threading.Thread.Sleep(1000);
  945.                     client.DoPost(param, "https://www.facebook.com/ajax/settings/account/email.php");
  946.  
  947.                     param = new NameValueCollection();
  948.                     param.Add("fb_dtsg", fb_dtsg);
  949.                     param.Add("primary_email", USER_ID + "@tinphuong.com");
  950.                     param.Add("remove_emails[0]", primary_email);
  951.                     param.Add("new_email", "");
  952.                     param.Add("__user", USER_ID);
  953.                     param.Add("__a", "1");
  954.                     System.Threading.Thread.Sleep(1000);
  955.                     client.DoPost(param, "https://www.facebook.com/ajax/settings/account/email.php");
  956.                     #endregion
  957.  
  958.                     #region - Remove phone number -
  959.                     System.Threading.Thread.Sleep(1000);
  960.                     client.DoGet("https://www.facebook.com/settings?tab=mobile");
  961.                     string strPhone = Utilities.GetRegexString(client.ResponseText, "phoneNumber", 2);
  962.                     if (!string.IsNullOrEmpty(strPhone))
  963.                     {
  964.                         param = new NameValueCollection();
  965.                         param.Add("fb_dtsg", Utilities.GetRegexString(client.ResponseText, "fb_dtsg", 1));
  966.                         param.Add("profile_id", USER_ID);
  967.                         param.Add("__user", USER_ID);
  968.                         param.Add("__a", "1");
  969.                         param.Add("phone_number", strPhone);
  970.                         client.DoPost(param, "https://www.facebook.com/ajax/settings/mobile/delete_phone.php");
  971.                     }
  972.                     #endregion
  973.                 }
  974.             }
  975.             return null;
  976.         }
  977.  
  978.         public FaceBook RegFBWeb()
  979.         {
  980.             FaceBook model = null;
  981.             FBExtraData extraData = new FBExtraData();
  982.  
  983.             WebClientEx client = new WebClientEx();
  984.             NameValueCollection param = new NameValueCollection();
  985.             client.DoGet("https://m.facebook.com/r.php?loc=bottom&refid=8");
  986.             if (client.Error == null)
  987.             {
  988.                 model = new FaceBook();
  989.                 model.Pass = new List<string>() { "0123", "0124", "0125", "0126", "0127", "098", "097", "096", "094", "092" }[new Random().Next(0, 10)] + new Random().Next(1000000, 9999999).ToString();
  990.                 string name = Utilities.GetMaleName(true);
  991.                 param = new NameValueCollection();
  992.                 param.Add("lsd", Utilities.GetRegexString(client.ResponseText, "lsd", 1));
  993.                 param.Add("charset_test", "€,´,€,´,水,Д,Є");
  994.                 param.Add("reg_instance", Utilities.GetRegexString(client.ResponseText, "reg_instance", 1));
  995.                 param.Add("cred_label", "email_or_phone");
  996.                 param.Add("submission_request", "true");
  997.                 param.Add("lastname", name.Split(' ')[0]);
  998.                 param.Add("firstname", name.Split(' ')[1]);
  999.                 param.Add("email", model.Pass);
  1000.                 param.Add("gender", new Random().Next(1, 3).ToString());
  1001.                 System.Threading.Thread.Sleep(12);
  1002.                 param.Add("day", new Random().Next(01, 28).ToString("00"));
  1003.                 System.Threading.Thread.Sleep(12);
  1004.                 param.Add("month", new Random().Next(01, 12).ToString("00"));
  1005.                 System.Threading.Thread.Sleep(12);
  1006.                 param.Add("year", new Random().Next(1980, 1990).ToString());
  1007.                 param.Add("pass", model.Pass);
  1008.                 param.Add("submit", "Đăng ký");
  1009.                 System.Threading.Thread.Sleep(5000);
  1010.                 client.DoPost(param, "https://m.facebook.com/r.php");
  1011.                 if (client.Response.ResponseUri.AbsolutePath.Contains("confirmemail.php"))
  1012.                 {
  1013.                     System.Threading.Thread.Sleep(5000);
  1014.                     client.DoGet("https://m.facebook.com/changeemail?");
  1015.                     if (client != null)
  1016.                     {
  1017.                         param = new NameValueCollection();
  1018.                         string USER_ID = Utilities.GetRegexString(client.ResponseText, "USER_ID", 2);
  1019.                         param.Add("fb_dtsg", Utilities.GetRegexString(client.ResponseText, "fb_dtsg", 1));
  1020.                         param.Add("charset_test", "€,´,€,´,水,Д,Є");
  1021.                         param.Add("old_email", "+84" + model.Pass.Substring(1));
  1022.                         param.Add("reg_instance", Utilities.GetRegexString(client.ResponseText, "reg_instance", 1));
  1023.                         param.Add("new", USER_ID + "@tinphuong.com");
  1024.                         param.Add("submit", "Thay đổi");
  1025.                         //param.Add("__req", "a");
  1026.                         param.Add("__ajax__", "true");
  1027.                         param.Add("__user", USER_ID);
  1028.                         System.Threading.Thread.Sleep(5000);
  1029.                         client.DoPost(param, "https://m.facebook.com/setemail");
  1030.                         client.DoGet("https://m.facebook.com/confirmemail.php?email_changed&__user=" + USER_ID + "&__req=b&__ajax__=true");
  1031.                         string strCode = Utilities.GetConfirmCode(param["new"]);
  1032.  
  1033.                         param = new NameValueCollection();
  1034.                         param.Add("fb_dtsg", Utilities.GetRegexString(client.ResponseText, "token", 2));
  1035.                         param.Add("charset_test", "€,´,€,´,水,Д,Є");
  1036.                         param.Add("c", strCode);
  1037.                         param.Add("submit", "Chấp nhận");
  1038.                         //param.Add("__req", "g");
  1039.                         param.Add("__ajax__", "true");
  1040.                         param.Add("__user", USER_ID);
  1041.  
  1042.                         client.DoPost(param, "https://m.facebook.com/confirmemail.php");
  1043.                         client.DoGet("https://m.facebook.com/home.php?confirmed_account");
  1044.                         System.Threading.Thread.Sleep(3000);
  1045.                         client.DoGet("https://www.facebook.com/ajax/settings/account/password.php?__user=" + USER_ID + "&__a=1&__req=v");
  1046.  
  1047.                         param = new NameValueCollection();
  1048.  
  1049.                         param.Add("fb_dtsg", Utilities.GetRegexString(client.ResponseText, "token", 2));
  1050.                         param.Add("password_strength", "2");
  1051.                         param.Add("password_old", model.Pass);
  1052.                         param.Add("password_new", USER_ID);
  1053.                         param.Add("password_confirm", USER_ID);
  1054.                         param.Add("__user", USER_ID);
  1055.                         param.Add("__a", "1");
  1056.                         //param.Add("__req", "6");
  1057.                         //param.Add("ttstamp","26581721109510410766839049103");
  1058.                         //param.Add("__rev  1512134
  1059.                         System.Threading.Thread.Sleep(5000);
  1060.                         client.DoPost(param, "https://www.facebook.com/ajax/settings/account/password.php");
  1061.                         model.Pass = USER_ID;
  1062.                         model.Login = USER_ID;
  1063.                         model.FBID = USER_ID;
  1064.                         if (LoginMobile(model, client))
  1065.                         {
  1066.                             client = new WebClientEx();
  1067.                             client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  1068.                             client.SetCookieV2 = false;
  1069.                             Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  1070.                             client.Authorization = dicData["access_token"].ToString();
  1071.                             string hash_id = Utilities.GetMd5Hash(DateTime.Now.Ticks.ToString());
  1072.                             hash_id = hash_id.Substring(0, 8) + "-" + hash_id.Substring(8, 4) + "-" + hash_id.Substring(12, 4) + "-" + hash_id.Substring(16, 4) + "-" + hash_id.Substring(20, 12);
  1073.                             #region - Upload profile picture -
  1074.                             if (Global.ListProfilePhotoLink.Count > 0)
  1075.                             {
  1076.                                 string id = UploadPhoto(client.Authorization, Global.ListProfilePhotoLink[0]);
  1077.                                 Global.ListProfilePhotoLink.RemoveAt(0);
  1078.                                 if (!string.IsNullOrEmpty(id))
  1079.                                 {
  1080.                                     param = new NameValueCollection();
  1081.  
  1082.                                     param.Add("batch", "[{\"method\":\"POST\",\"body\":\"qn=" + hash_id
  1083.                                  + "&scaled_crop_rect=%7B%22y%22%3A0%2C%22height%22%3A1%2C%22width%22%3A1%2C%22x%22%3A0%7D&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=publish-photo\",\"name\":\"publish\",\"omit_response_on_success\":false,"
  1084.                                  + "\"relative_url\":\"" + model.FBID + "/picture/" + id + "\"}]");
  1085.                                     param.Add("fb_api_caller_class", "com.facebook.photos.upload.protocol.PhotoPublisher");
  1086.                                     client.DoPost(param, "https://graph.facebook.com/?include_headers=false&locale=vi_VN&client_country_code=VN");
  1087.                                     extraData.LastUpdateProfilePhoto = DateTime.Now;
  1088.                                 }
  1089.                             }
  1090.                             #endregion
  1091.                             param = new NameValueCollection();
  1092.                             param.Add("format", "JSON");
  1093.                             param.Add("nux_id", "ANDROID_NEW_ACCOUNT_WIZARD");
  1094.                             param.Add("step", "upload_profile_pic");
  1095.                             param.Add("status", "COMPLETE");
  1096.                             param.Add("extra_data", "{}");
  1097.                             param.Add("locale", "vi_VN");
  1098.                             param.Add("client_country_code", "VN");
  1099.                             param.Add("method", "user.updateNuxStatus");
  1100.                             param.Add("fb_api_req_friendly_name", "updateNuxStatus");
  1101.                             param.Add("fb_api_caller_class", "com.facebook.nux.status.UpdateNuxStatusMethod");
  1102.                             System.Threading.Thread.Sleep(1000);
  1103.                             client.DoPost(param, "https://api.facebook.com/method/user.updateNuxStatus");
  1104.  
  1105.                             #region - Update work and class info -
  1106.                             param = new NameValueCollection();
  1107.                             param.Add("work", ("[{'id':'" + Utilities.GetProfileInfo(4) + "','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android'}]").Replace("'", "\""));
  1108.                             param.Add("education", ("[{'id':'" + Utilities.GetProfileInfo(3) + "','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android','type':'College'},{'id':'" + Utilities.GetProfileInfo(2) + "','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android','type':'High School'}]").Replace("'", "\""));
  1109.                             param.Add("location", "{'id':'108458769184495','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android'}".Replace("'", "\""));
  1110.                             param.Add("hometown", "{'id':'108458769184495','privacy':'{\\'value\\':\\'EVERYONE\\'}','ref':'nux_android'}".Replace("'", "\""));
  1111.                             param.Add("locale", "vi_VN");
  1112.                             param.Add("client_country_code", "VN");
  1113.                             param.Add("fb_api_req_friendly_name", "save_core_profile_info");
  1114.                             client.DoPost(param, "https://graph.facebook.com/me");
  1115.                             extraData.UpdatedProfileInfo = true;
  1116.                             #endregion
  1117.                             param = new NameValueCollection();
  1118.                             param.Add("format", "JSON");
  1119.                             param.Add("nux_id", "ANDROID_NEW_ACCOUNT_WIZARD");
  1120.                             param.Add("step", "classmates_coworkers");
  1121.                             param.Add("status", "COMPLETE");
  1122.                             param.Add("extra_data", "{}");
  1123.                             param.Add("locale", "vi_VN");
  1124.                             param.Add("client_country_code", "VN");
  1125.                             param.Add("method", "user.updateNuxStatus");
  1126.                             param.Add("fb_api_req_friendly_name", "updateNuxStatus");
  1127.                             param.Add("fb_api_caller_class", "com.facebook.nux.status.UpdateNuxStatusMethod");
  1128.                             System.Threading.Thread.Sleep(1000);
  1129.                             client.DoPost(param, "https://api.facebook.com/method/user.updateNuxStatus");
  1130.                             if (client.ResponseText.ToLower().Trim() != "true") return null;
  1131.                             param = new NameValueCollection();
  1132.                             param.Add("format", "JSON");
  1133.                             param.Add("nux_id", "ANDROID_NEW_ACCOUNT_WIZARD");
  1134.                             param.Add("step", "contact_importer");
  1135.                             param.Add("status", "COMPLETE");
  1136.                             param.Add("extra_data", "{}");
  1137.                             param.Add("locale", "vi_VN");
  1138.                             param.Add("client_country_code", "VN");
  1139.                             param.Add("method", "user.updateNuxStatus");
  1140.                             param.Add("fb_api_req_friendly_name", "updateNuxStatus");
  1141.                             param.Add("fb_api_caller_class", "com.facebook.nux.status.UpdateNuxStatusMethod");
  1142.                             System.Threading.Thread.Sleep(1000);
  1143.                             client.DoPost(param, "https://api.facebook.com/method/user.updateNuxStatus");
  1144.  
  1145.                             #region - update cover photo -
  1146.                             if (Global.LisCoverPhotoLink.Count > 0)
  1147.                             {
  1148.                                 string id = UploadPhoto(client.Authorization, Global.LisCoverPhotoLink[Global.LisCoverPhotoLink.Count - 1]);
  1149.                                 Global.LisCoverPhotoLink.RemoveAt(Global.LisCoverPhotoLink.Count - 1);
  1150.  
  1151.                                 if (!string.IsNullOrEmpty(id))
  1152.                                 {
  1153.                                     param = new NameValueCollection();
  1154.                                     param.Add("batch", "[{\"method\":\"POST\",\"body\":\"qn=" + hash_id
  1155.                                      + "&photo=" + id + "&focus_y=0&locale=vi_VN&client_country_code=VN&fb_api_req_friendly_name=publish-photo\",\"name\":\"publish\",\"omit_response_on_success\":false,"
  1156.                                      + "\"relative_url\":\"" + model.FBID + "/cover\"}]");
  1157.                                     param.Add("fb_api_caller_class", "com.facebook.photos.upload.protocol.PhotoPublisher");
  1158.                                     client.DoPost(param, "https://graph.facebook.com/?include_headers=false&locale=vi_VN&client_country_code=VN");
  1159.                                     extraData.LastUpdateCoverPhoto = DateTime.Now;
  1160.                                 }
  1161.                             }
  1162.                             #endregion
  1163.                             //Like(model, "639987956113732");
  1164.                             Debug.WriteLine("-- SetExtraData --");
  1165.                             SetExtraData(model, extraData);
  1166.                             Debug.WriteLine("-- End INNER Reg --");
  1167.                             return model;
  1168.                         }
  1169.  
  1170.  
  1171.                     }
  1172.                 }
  1173.             }
  1174.  
  1175.             return null;
  1176.         }
  1177.  
  1178.         public bool PostStatus(FaceBook model)
  1179.         {
  1180.             try
  1181.             {
  1182.                 FBExtraData extraData = GetExtraData(model);
  1183.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  1184.                 int iRD = new Random().Next(1, 4500);
  1185.                 string strStatus = Global.DBContext.StatusData.Where(m => m.ID == iRD).FirstOrDefault().Text;
  1186.                 //strStatus = HttpUtility.UrlEncode(strStatus);
  1187.                 NameValueCollection param = new NameValueCollection();
  1188.                 param.Add("access_token", dicData["access_token"].ToString());
  1189.                 param.Add("format", "json");
  1190.                 param.Add("method", "post");
  1191.                 param.Add("pretty", "0");
  1192.                 param.Add("suppress_http_code", "1");
  1193.                 param.Add("message", strStatus);
  1194.                 WebClientEx clientAPI = new WebClientEx();
  1195.                 clientAPI.DoPost(param, "https://graph.facebook.com/v2.1/me/feed");
  1196.                 if (clientAPI.Error == null)
  1197.                 {
  1198.                     return true;
  1199.                 }
  1200.                 else if (!string.IsNullOrEmpty(clientAPI.ResponseText) && clientAPI.ResponseText.Contains("\"error\""))
  1201.                 {
  1202.                     return false;
  1203.                 }
  1204.                 else
  1205.                 {
  1206.                     return true;
  1207.                 }
  1208.             }
  1209.             catch
  1210.             {
  1211.             }
  1212.             return false;
  1213.         }
  1214.  
  1215.         public string UploadPhoto(string access_token, string strLink)
  1216.         {
  1217.             try
  1218.             {
  1219.                 if (!string.IsNullOrEmpty(strLink))
  1220.                 {
  1221.                     NameValueCollection param = new NameValueCollection();
  1222.                     param.Add("access_token", access_token);
  1223.                     param.Add("format", "json");
  1224.                     param.Add("method", "post");
  1225.                     param.Add("pretty", "0");
  1226.                     param.Add("suppress_http_code", "1");
  1227.                     param.Add("url", strLink);
  1228.                     WebClientEx clientAPI = new WebClientEx();
  1229.                     clientAPI.DoPost(param, "https://graph.facebook.com/v2.1/me/photos");
  1230.                     if (!string.IsNullOrEmpty(clientAPI.ResponseText))
  1231.                     {
  1232.                         Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(clientAPI.ResponseText);
  1233.                         if (dicData.ContainsKey("id"))
  1234.                         {
  1235.                             string id = dicData["id"].ToString();
  1236.                             return id;
  1237.                         }
  1238.                     }
  1239.                 }
  1240.             }
  1241.             catch { }
  1242.             return string.Empty;
  1243.         }
  1244.  
  1245.         public bool ConfirmEmail(FaceBook model)
  1246.         {
  1247.             try
  1248.             {
  1249.                 if (model.Login.EndsWith("@vuathuthanh.net")) return false;
  1250.                 WebClientEx client = new WebClientEx();
  1251.                 client.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  1252.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  1253.                 client.Authorization = dicData["access_token"].ToString();
  1254.  
  1255.                 NameValueCollection param = new NameValueCollection();
  1256.                 string strNewEmail = model.Login.Substring(0, model.Login.IndexOf("@")) + "@vuathuthanh.net";
  1257.                 param.Add("add_contactpoint", strNewEmail);
  1258.                 param.Add("add_contactpoint_type", "EMAIL");
  1259.                 param.Add("format", "json");
  1260.                 param.Add("locale", "vi_VN");
  1261.                 param.Add("client_country_code", "VN");
  1262.                 param.Add("fb_api_req_friendly_name", "editRegistrationContactpoint");
  1263.                 param.Add("method", "user.editregistrationcontactpoint");
  1264.                 param.Add("fb_api_caller_class", "com.facebook.confirmation.protocol.EditRegistrationContactpointMethod");
  1265.  
  1266.                 client.DoPost(param, "https://api.facebook.com/method/user.editregistrationcontactpoint");
  1267.                 if (!string.IsNullOrEmpty(client.ResponseText) && client.ResponseText == "true")
  1268.                 {
  1269.                     System.Threading.Thread.Sleep(3000);
  1270.                     int iTry = 0;
  1271.                     bool bFindEmail = false;
  1272.                     while (iTry < 3 && !bFindEmail)
  1273.                     {
  1274.                         Pop3Client pop3 = new Pop3Client();
  1275.                         pop3.Connect("vuathuthanh.net", 110, false);
  1276.                         pop3.Authenticate("mail@vuathuthanh.net", "uxBa2@05");
  1277.                         Dictionary<string, string> dicMail = new Dictionary<string, string>();
  1278.                         for (int iIndex = pop3.GetMessageCount(); iIndex > 0; iIndex--)
  1279.                         {
  1280.                             OpenPop.Mime.Message message = pop3.GetMessage(iIndex);
  1281.                             if (message.Headers.To[0].MailAddress.Address == strNewEmail)
  1282.                             {
  1283.                                 var strBody = message.MessagePart.MessageParts[0].BodyEncoding.GetString(message.MessagePart.MessageParts[0].Body);
  1284.                                 string code = Regex.Match(strBody, @"&code=(?<val>[0-9]+)&").Groups["val"].Value;
  1285.                                 if (!string.IsNullOrEmpty(code))
  1286.                                 {
  1287.                                     param = new NameValueCollection();
  1288.                                     param.Add("normalized_contactpoint", strNewEmail);
  1289.                                     param.Add("contactpoint_type", "EMAIL");
  1290.                                     param.Add("code", code);
  1291.                                     param.Add("source", "ANDROID_DIALOG_API");
  1292.                                     param.Add("format", "json");
  1293.                                     param.Add("locale", "vi_VN");
  1294.                                     param.Add("client_country_code", "VN");
  1295.                                     param.Add("fb_api_req_friendly_name", "confirmContactpoint");
  1296.                                     param.Add("method", "user.confirmcontactpoint");
  1297.                                     param.Add("fb_api_caller_class", "com.facebook.confirmation.protocol.ConfirmContactpointMethod");
  1298.                                     client.DoPost(param, "https://api.facebook.com/method/user.confirmcontactpoint");
  1299.                                     //if (!string.IsNullOrEmpty(client.ResponseText) && client.ResponseText == "true")
  1300.                                     {
  1301.                                         bFindEmail = true;
  1302.                                     }
  1303.                                 }
  1304.                                 try
  1305.                                 {
  1306.                                     pop3.DeleteMessage(iIndex);
  1307.                                 }
  1308.                                 catch
  1309.                                 {
  1310.                                 }
  1311.                             }
  1312.                             if (bFindEmail) break;
  1313.                         }
  1314.                         if (bFindEmail)
  1315.                         {
  1316.                             pop3.DeleteAllMessages();
  1317.                             pop3.Disconnect();
  1318.                             model.Login = strNewEmail;
  1319.                             return true;
  1320.                         }
  1321.                         else
  1322.                         {
  1323.                             System.Threading.Thread.Sleep(3000);
  1324.                             iTry++;
  1325.                         }
  1326.                         pop3.Disconnect();
  1327.                     }
  1328.                 }
  1329.                 else if (!string.IsNullOrEmpty(client.ResponseText) && client.ResponseText.Contains("Account already has confirmed email or phone"))
  1330.                 {
  1331.                     model.Login = strNewEmail;
  1332.                     return true;
  1333.                 }
  1334.             }
  1335.             catch (Exception ex)
  1336.             {
  1337.                 throw ex;
  1338.             }
  1339.             return false;
  1340.         }
  1341.  
  1342.         public void Like(FaceBook model, string id)
  1343.         {
  1344.             try
  1345.             {
  1346.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  1347.                 NameValueCollection param = new NameValueCollection();
  1348.                 param.Add("access_token", dicData["access_token"].ToString());
  1349.                 param.Add("format", "json");
  1350.                 param.Add("method", "post");
  1351.                 param.Add("pretty", "0");
  1352.                 param.Add("suppress_http_code", "1");
  1353.                 WebClientEx clientAPI = new WebClientEx();
  1354.                 clientAPI.DoPost(param, "https://graph.facebook.com/v2.1/" + id + "/likes");
  1355.  
  1356.             }
  1357.             catch { }
  1358.         }
  1359.  
  1360.         public void Like(string access_token, string id)
  1361.         {
  1362.             try
  1363.             {
  1364.                 NameValueCollection param = new NameValueCollection();
  1365.                 param.Add("access_token", access_token);
  1366.                 param.Add("format", "json");
  1367.                 param.Add("method", "post");
  1368.                 param.Add("pretty", "0");
  1369.                 param.Add("suppress_http_code", "1");
  1370.                 WebClientEx clientAPI = new WebClientEx();
  1371.                 clientAPI.DoPost(param, "https://graph.facebook.com/v2.1/" + id + "/likes");
  1372.             }
  1373.             catch { }
  1374.         }
  1375.  
  1376.         public void Share(Page page, string id, string strMessage)
  1377.         {
  1378.             try
  1379.             {
  1380.                 string hash_id = Utilities.GetMd5Hash(DateTime.Now.Ticks.ToString());
  1381.                 hash_id = hash_id.Substring(0, 8) + "-" + hash_id.Substring(8, 4) + "-" + hash_id.Substring(12, 4) + "-" + hash_id.Substring(16, 4) + "-" + hash_id.Substring(20, 12);
  1382.                 WebClientEx clientEx = new WebClientEx();
  1383.                 clientEx.RequestType = WebClientEx.RequestTypeEnum.FaceBook;
  1384.                 clientEx.Authorization = page.AccessToken;
  1385.                 NameValueCollection param = new NameValueCollection();
  1386.  
  1387.                 param.Add("batch", ("[{'method':'POST','body':'message=" + strMessage + "&nectar_module=pages_identity_ufi&composer_session_id=" + hash_id + "&qn=" + hash_id + "&idempotence_token=" + hash_id + "&audience_exp=true&attach_place_suggestion=true&format=json&id=" + id + "&to=" + page.PageID + "&fb_api_req_friendly_name=graphObjectShare','name':'graphObjectShares','omit_response_on_success':false,'relative_url':'sharedposts'}]").Replace("'", "\""));
  1388.                 param.Add("fb_api_caller_class", "com.facebook.composer.publish.ComposerPublishServiceHandler");
  1389.                 clientEx.DoPost(param, "https://graph.facebook.com/?include_headers=false&decode_body_json=false&streamable_json_response=true&locale=vi_VN&client_country_code=VN");
  1390.                 if (clientEx.Error == null && !string.IsNullOrEmpty(clientEx.ResponseText))
  1391.                 {
  1392.                 }
  1393.             }
  1394.             catch { }
  1395.         }
  1396.  
  1397.         public void Comment(FaceBook model, string id)
  1398.         {
  1399.             try
  1400.             {
  1401.                 Dictionary<string, object> dicData = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(model.MBLoginText);
  1402.                 Random r = new Random();
  1403.                 NameValueCollection param = new NameValueCollection();
  1404.                 param.Add("access_token", dicData["access_token"].ToString());
  1405.                 param.Add("format", "json");
  1406.                 param.Add("method", "post");
  1407.                 param.Add("pretty", "0");
  1408.                 param.Add("suppress_http_code", "1");
  1409.                 int iRD = new Random().Next(1, 4500);
  1410.                 string strStatus = Global.DBContext.StatusData.Where(m => m.ID == iRD).FirstOrDefault().Text;
  1411.                 param.Add("message", strStatus);
  1412.                 WebClientEx clientAPI = new WebClientEx();
  1413.                 clientAPI.DoPost(param, "https://graph.facebook.com/v2.1/" + id + "/comments");
  1414.             }
  1415.             catch { }
  1416.         }
  1417.  
  1418.         private FBExtraData GetExtraData(FaceBook model)
  1419.         {
  1420.             FBExtraData fbExtraData = new FBExtraData();
  1421.             if (model != null && !string.IsNullOrEmpty(model.ExtraData))
  1422.             {
  1423.                 fbExtraData = new JavaScriptSerializer().Deserialize<FBExtraData>(model.ExtraData);
  1424.             }
  1425.             return fbExtraData;
  1426.         }
  1427.  
  1428.         private void SetExtraData(FaceBook model, FBExtraData extraData)
  1429.         {
  1430.             if (!extraData.CreateDate.HasValue) extraData.CreateDate = DateTime.Now;
  1431.             model.ExtraData = new JavaScriptSerializer().Serialize(extraData);
  1432.         }
  1433.  
  1434.         public void Dispose()
  1435.         {
  1436.             GC.SuppressFinalize(this);
  1437.         }
  1438.     }
  1439. }
Add Comment
Please, Sign In to add comment