Пример #1
0
        //Code added by Lijo For tweeting with images in the wait and reply module
        public void TweetMessageWithImage(ref Globussoft.GlobusHttpHelper globusHttpHelper, string postAuthenticityToken, string tweetMessage, string ImageFilePath, out string status)
        {
            string status1     = string.Empty;
            bool   IsLocalFile = true;
            string MediaId     = string.Empty;

            ///Read Image Data in Byte
            ///convert byte in base 64 string
            try
            {
                string _base64String = Convert.ToBase64String(File.ReadAllBytes(ImageFilePath));

                try
                {
                    _base64String = StringEncoderDecoder.EncodeBase64String(_base64String);
                }
                catch
                {
                }
                ///call method for posting
                ///
                string txid = (UnixTimestampFromDateTime(System.DateTime.Now) * 1000).ToString();

                string postData  = "authenticity_token=" + postAuthenticityToken + "&iframe_callback=&media=" + _base64String + "&upload_id=" + txid + "&origin=https%3A%2F%2Ftwitter.com";
                string response_ = globusHttpHelper.postFormData(new Uri("https://upload.twitter.com/i/media/upload.iframe?origin=https%3A%2F%2Ftwitter.com"), postData, "https://twitter.com/", "", "", "", "https://twitter.com/");

                MediaId = globusHttpHelper.getBetween(response_, "snowflake_media_id\":", ",").Replace("snowflake_media_id\":", "").Trim();

                string finalpostdata = "authenticity_token=" + postAuthenticityToken + "&media_ids=" + MediaId + "&place_id=&status=" + tweetMessage.Replace(" ", "+") + "&tagged_users=";

                response_ = globusHttpHelper.postFormData(new Uri("https://twitter.com/i/tweet/create"), finalpostdata, "https://twitter.com/", "", "XMLHttpRequest", "", "https://twitter.com/");

                //globusHttpHelper.HttpUploadImageFileWithMessage("https://upload.twitter.com/i/tweet/create_with_media.iframe", ImageFilePath, "media_data[]", "application/octet-stream", nvc, true, ref status1);

                //if (status1 == "okay")
                //{
                //    status1 = "posted";
                //}

                if (response_.Contains("tweet_id"))
                {
                    status1 = "posted";
                }
            }
            catch (Exception ex)
            {
                Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetMessageWithImagePostData() -- Tweet -- que_TweetMessages_Hashtags --> " + ex.Message, Globals.Path_TweetingErroLog);
                Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> TweetMessageWithImagePostData() --  Tweet -- que_TweetMessages_Hashtags  --> " + ex.Message, Globals.Path_TweetAccountManager);
            }
            status = status1;
        }
Пример #2
0
        public void Tweet(ref Globussoft.GlobusHttpHelper globusHttpHelper, string postAuthenticityToken, string tweetMessage, out string status)
        {
            string tweetdata  = string.Empty;
            string tweetUrl   = string.Empty;
            string postaTweet = string.Empty;

            try
            {
                //string abc = tweetMessage.Replace("�", " ");
                //Post Tweet To Account
                tweetdata = "authenticity_token=" + postAuthenticityToken + "&place_id=&status=" + Uri.EscapeDataString(tweetMessage);
                tweetUrl  = "https://twitter.com/i/tweet/create";

                postaTweet = globusHttpHelper.postFormData(new Uri(tweetUrl), tweetdata, "https://twitter.com/", "XMLHttpRequest", "", "", "");


                ///Old Twitter 1.0 API code
                //string TweetData = "include_entities=true&status=" + HttpUtility.UrlEncode(tweetMessage) + "&post_authenticity_token=" + postAuthenticityToken;
                //string res_PostTweet = globusHttpHelper.postFormData(new Uri("https://api.twitter.com/1/statuses/update.json"), TweetData, "https://api.twitter.com/receiver.html", postAuthenticityToken, "XMLHttpRequest", "true", "");
                /////

                var message = (Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(postaTweet))["message"];

                //string ss=Uri.en

                if (postaTweet.Contains("Your Tweet was posted!") || message.ToString().Contains("आपका ट्वीट पोस्ट हो गया") || postaTweet.Contains("tweet_id") || message.Contains("tweet_id") || message.ToString().Contains("Your Tweet was posted!") || postaTweet.Contains(message.ToString()))
                {
                    status = "posted";
                }
                else if (postaTweet.Contains("Your Tweet to") && postaTweet.Contains("has been sent"))
                {
                    status = "posted";
                }

                else
                {
                    status = "not posted";
                }
            }
            catch (Exception ex)
            {
                try
                {
                    if (ex.Message.Contains("Stream was not readable"))
                    {
                        if (!string.IsNullOrEmpty(Globals.DBCUsername) && !string.IsNullOrEmpty(Globals.DBCPassword))
                        {
                            string _tempCaptcha     = globusHttpHelper.getHtmlfromUrl(new Uri("https://www.google.com/recaptcha/api/challenge?k=6LfbTAAAAAAAAE0hk8Vnfd1THHnn9lJuow6fgulO&ajax=1&cachestop=0.88776721409522&lang=en"), "", "");
                            string captchaChallenge = globusHttpHelper.getBetween(_tempCaptcha, "challenge : '", ",").Replace("challenge : '", "").Replace("'", "");
                            string ImageUrl         = "https://www.google.com/recaptcha/api/image?c=" + captchaChallenge;

                            WebClient webclient   = new WebClient();
                            string    captchaText = string.Empty;
                            if (!string.IsNullOrEmpty(captchaChallenge))
                            {
                                try
                                {
                                    //WebIP IPObj = new WebIP("http://192.227.234.242:80");
                                    //IPObj.Credentials = CredentialCache.DefaultCredentials;
                                    //webclient.IP = IPObj;

                                    byte[] args = webclient.DownloadData(ImageUrl);

                                    string[] arr1 = new string[] { Globals.DBCUsername, Globals.DBCPassword, "" };

                                    captchaText = DecodeDBC(arr1, args);
                                }
                                catch { }
                            }

                            if (!string.IsNullOrEmpty(captchaText))
                            {
                                string mainUrl  = "https://twitter.com/account/challenge?challenge=" + captchaChallenge + "&challenge_name=Captcha&response=" + captchaText.Replace(" ", "+");
                                string response = globusHttpHelper.getHtmlfromUrl(new Uri(mainUrl), "", "", "");

                                postaTweet = globusHttpHelper.postFormData(new Uri(tweetUrl), tweetdata, "https://twitter.com/", "XMLHttpRequest", "", "", "");

                                var message = (Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(postaTweet))["message"];

                                //string ss=Uri.en

                                if (postaTweet.Contains("Your Tweet was posted!") || message.ToString().Contains("आपका ट्वीट पोस्ट हो गया") || postaTweet.Contains("tweet_id") || message.Contains("tweet_id") || message.ToString().Contains("Your Tweet was posted!") || postaTweet.Contains(message.ToString()))
                                {
                                    status = "posted";
                                }
                                else if (postaTweet.Contains("Your Tweet to") && postaTweet.Contains("has been sent"))
                                {
                                    status = "posted";
                                }

                                else
                                {
                                    status = "not posted";
                                }
                            }
                            else
                            {
                                status = "not posted";
                            }
                        }
                        else
                        {
                            status = "not posted";
                        }
                    }
                    else
                    {
                        status = "not posted";
                        Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Tweeter() -- Tweet() --> " + ex.Message, Globals.Path_FollowerErroLog);
                        Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> Tweeter() -- Tweet()  --> " + ex.Message, Globals.Path_TwtErrorLogs);
                    }
                }
                catch (Exception exp)
                {
                    status = "not posted";
                    Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> Tweeter() -- Tweet() --> " + exp.Message, Globals.Path_FollowerErroLog);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Change follow code  after API change
        /// </summary>
        /// <param name="thisHttpHelpr"></param>
        /// <param name="ForeignhttpHelpr"></param>

        #region FollowUsingProfileID_New
        public void FollowUsingProfileID_New(ref Globussoft.GlobusHttpHelper globusHttpHelper, string pgSrc, string postAuthenticityToken, string user_id_toFollow, out string status)
        {
            try
            {
                string data_user_id = string.Empty;
                string PostData     = string.Empty;

                if (NumberHelper.ValidateNumber(user_id_toFollow))
                {
                    string tempScreenName = string.Empty;
                    data_user_id = user_id_toFollow;
                    string pageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/intent/user?user_id=" + user_id_toFollow), "", "");
                    if (string.IsNullOrEmpty(pageSource))
                    {
                        pageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/intent/user?user_id=" + user_id_toFollow), "", "");
                    }
                    tempScreenName = globusHttpHelper.getBetween(pageSource, "<span class=\"name\">", "</span>");
                    if (!string.IsNullOrEmpty(tempScreenName))
                    {
                        pageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + tempScreenName), "", "");
                    }

                    if (!string.IsNullOrEmpty(pageSource))
                    {
                        try
                        {
                            int startIndx = pageSource.IndexOf("data-user-id=\"") + "data-user-id=\"".Length;
                            int endIndx   = pageSource.IndexOf("\"", startIndx);
                            userID = pageSource.Substring(startIndx, endIndx - startIndx);
                        }
                        catch { }

                        if (string.IsNullOrEmpty(userID))
                        {
                            userID = string.Empty;
                            //string[] useridarr = System.Text.RegularExpressions.Regex.Split(pageSource, "data-user-id="); //account-group js-mini-current-user
                            string[] useridarr = System.Text.RegularExpressions.Regex.Split(pageSource, "account-group js-mini-current-user");
                            //foreach (string useridarr_item in useridarr)
                            //{
                            //    if (useridarr_item.Contains("data-screen-name="))
                            //    {
                            //        userID = useridarr_item.Substring(0 + 1, useridarr_item.IndexOf("data-screen-name=") - 3);
                            //        break;
                            //    }
                            //}

                            try
                            {
                                userID = Utils.getBetween(useridarr[1], "data-user-id=\"", "\"");
                            }
                            catch { };
                        }
                    }
                }
                else
                {
                    try
                    {
                        string data_id    = string.Empty;
                        string pageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + user_id_toFollow), "", "");
                        if (string.IsNullOrEmpty(pageSource))
                        {
                            pageSource = globusHttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + user_id_toFollow), "", "");
                        }

                        try
                        {
                            int startIndx = pageSource.IndexOf("data-user-id=\"") + "data-user-id=\"".Length;
                            int endIndx   = pageSource.IndexOf("\"", startIndx);
                            userID = pageSource.Substring(startIndx, endIndx - startIndx);
                            if (string.IsNullOrEmpty(userID))
                            {
                                try
                                {
                                    //string[] GetUserId = System.Text.RegularExpressions.Regex.Split(pageSource, "user-actions btn-group not-following not-muting");
                                    string[] useridarr = System.Text.RegularExpressions.Regex.Split(pageSource, "account-group js-mini-current-user");

                                    try
                                    {
                                        userID = Utils.getBetween(useridarr[1], "data-user-id=\"", "\"");
                                    }
                                    catch { };
                                }
                                catch { };
                            }
                        }
                        catch { }

                        if (string.IsNullOrEmpty(userID))
                        {
                            userID = string.Empty;
                            string[] useridarr = System.Text.RegularExpressions.Regex.Split(pageSource, "data-user-id=");
                            foreach (string useridarr_item in useridarr)
                            {
                                if (useridarr_item.Contains("data-screen-name="))
                                {
                                    userID = useridarr_item.Substring(0 + 1, useridarr_item.IndexOf("data-screen-name=") - 3);
                                    break;
                                }
                            }
                        }


                        if (globusHttpHelper.gResponse.ResponseUri.ToString().Contains("suspended"))
                        {
                            status = "not followed";
                            Log(user_id_toFollow + " :-  Account is suspended ");
                            return;
                        }

                        string[] data_id1 = System.Text.RegularExpressions.Regex.Split(pageSource, "data-user-id=");
                        if (pageSource.Contains("js-stream-item stream-item stream-item"))
                        {
                            if (pageSource.Contains("profile-card-inner"))
                            {
                                int    startindex = pageSource.IndexOf("profile-card-inner");
                                string start      = pageSource.Substring(startindex).Replace("profile-card-inner", "");
                                int    endindex   = start.IndexOf("\">");
                                string end        = start.Substring(start.IndexOf("data-user-id="), endindex - start.IndexOf("data-user-id=")).Replace("data-user-id=", "").Replace("\"", "");
                                data_user_id = end.Trim();
                            }
                            else
                            {
                                try
                                {
                                    //int startindex = pageSource.IndexOf("ProfileTweet-authorDetails\">");
                                    //string start = pageSource.Substring(startindex).Replace("ProfileTweet-authorDetails\">", "");
                                    //int endindex = start.IndexOf("\">");
                                    //string end = start.Substring(start.IndexOf("data-user-id="), endindex - start.IndexOf("data-user-id=")).Replace("data-user-id=", "").Replace("\"", "");
                                    //data_user_id = end.Trim();

                                    string[] getDataUserID = System.Text.RegularExpressions.Regex.Split(pageSource, "ProfileNav");
                                    data_user_id = Utils.getBetween(getDataUserID[1], "data-user-id=\"", "\"");
                                }
                                catch { };
                            }
                        }
                        else
                        {
                            try
                            {
                                int    startindex = pageSource.IndexOf("profile_id");
                                string start      = pageSource.Substring(startindex).Replace("profile_id", "");
                                int    endindex   = start.IndexOf(",");
                                string end        = start.Substring(0, endindex).Replace("&quot;", "").Replace("\"", "").Replace(":", "").Trim();
                                data_user_id = end.Trim();
                            }
                            catch { }

                            if (string.IsNullOrEmpty(data_user_id))
                            {
                                try
                                {
                                    int    startindex = pageSource.IndexOf("ProfileTweet-authorDetails\">");
                                    string start      = pageSource.Substring(startindex).Replace("ProfileTweet-authorDetails\">", "");
                                    int    endindex   = start.IndexOf("\">");
                                    string end        = start.Substring(start.IndexOf("data-user-id="), endindex - start.IndexOf("data-user-id=")).Replace("data-user-id=", "").Replace("\"", "");
                                    data_user_id = end.Trim();
                                }
                                catch { }
                            }

                            if (string.IsNullOrEmpty(data_user_id))
                            {
                                try
                                {
                                    int startindex = pageSource.IndexOf("stats js-mini-profile-stats \" data-user-id=\"");
                                    if (startindex == -1)
                                    {
                                        startindex = pageSource.IndexOf("user-actions btn-group not-following not-muting \" data-user-id=\"");
                                    }
                                    if (startindex == -1)
                                    {
                                        startindex = pageSource.IndexOf("user-actions btn-group not-following not-muting protected\" data-user-id=\"");
                                    }
                                    string start = pageSource.Substring(startindex).Replace("stats js-mini-profile-stats \" data-user-id=\"", "").Replace("user-actions btn-group not-following not-muting \" data-user-id=\"", "").Replace("user-actions btn-group not-following not-muting protected\" data-user-id=\"", "").Trim();
                                    //int endindex = start.IndexOf("\">");
                                    int    endindex = start.IndexOf("\"");
                                    string end      = start.Substring(0, endindex);
                                    data_user_id = end.Replace("\"", "");
                                }
                                catch { }
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingProfileID1()-->  " + err.Message, Globals.Path_FollowerErroLog);
                    }
                }
                DataSet dt            = DataBaseHandler.SelectQuery("SELECT * FROM tb_user_follower_details Where followerId = '" + data_user_id + "' and userId = '" + userID + "' ", "tb_user_follower_details");
                int     count_NO_RoWs = dt.Tables[0].Rows.Count;
                if (count_NO_RoWs == 0)
                {
                    if (!string.IsNullOrEmpty(data_user_id))
                    {
                        PostData = "authenticity_token=" + postAuthenticityToken + "&user_id=" + data_user_id;
                        string res_PostFollow = globusHttpHelper.postFormData(new Uri("https://twitter.com/i/user/follow"), PostData, "https://twitter.com/" + user_id_toFollow, string.Empty, "XMLHttpRequest", "true", "");

                        try
                        {
                            if (!string.IsNullOrEmpty(user_id_toFollow) && !string.IsNullOrEmpty(data_user_id))
                            {
                                // string query = "INSERT INTO tb_UsernameDetails (Username , Userid) VALUES ('" + user_id_toFollow + "' ,'" + data_user_id + "') ";
                                string query = "INSERT INTO  tb_user_follower_details (followerName,followerId,userId) VALUES ('" + user_id_toFollow + "' ,'" + data_user_id + "','" + userID + "') ";
                                DataBaseHandler.InsertQuery(query, "tb_UsernameDetails");
                            }
                        }
                        catch (Exception ex)
                        {
                            Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingProfileID_New() -->insertingdataintodatabase--> " + ex.Message, Globals.Path_FollowerErroLog);
                            Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> FollowUsingProfileID_New() -->insertingdataintodatabase--> " + ex.Message, Globals.Path_TwtErrorLogs);
                        }
                        status = "followed";
                        if (res_PostFollow.Contains("pending"))
                        {
                            status = "pending";
                        }
                        else if (res_PostFollow.Contains("following"))
                        {
                            status = "followed";
                        }
                    }
                    else
                    {
                        status = "not followed";
                        Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingProfileID1()(User ID is null) ", Globals.Path_FollowerErroLog);
                    }
                }
                else
                {
                    status = "Already Followed";
                    Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingProfileID1()--> DataBase Insert error ", Globals.Path_FollowerErroLog);
                    return;
                }
            }
            catch (Exception ex)
            {
                status = "not followed";
                //Log("Method>>  FollowUsingProfileID  --- class>>  Follower.cs : Follow Exception " + ex.Message);
                Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> FollowUsingProfileID() --> " + ex.Message, Globals.Path_FollowerErroLog);
                Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> FollowUsingProfileID() --> " + ex.Message, Globals.Path_TwtErrorLogs);
            }
        }