コード例 #1
0
        public static string GetUserIDFromUsername(string username, out string Status)
        {
            string GetStatus = string.Empty;
            Globussoft.GlobusHttpHelper httpHelper = new Globussoft.GlobusHttpHelper();

            clsDBQueryManager DB = new clsDBQueryManager();
            DataSet ds = DB.GetUserId(username);
            string user_id = string.Empty;

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dataRow in ds.Tables["tb_UsernameDetails"].Rows)
                {
                    user_id = dataRow.ItemArray[0].ToString();
                    Status = "No Error";
                    return user_id;
                }
            }


            try
            {
                string id = string.Empty;

                ChilkatHttpHelpr httpHelper1 = new ChilkatHttpHelpr();
                string pagesource = httpHelper1.GetHtml("https://api.twitter.com/1/users/show.xml?screen_name=" + username);

                if (!pagesource.Contains("Rate limit exceeded. Clients may not make more than 150 requests per hour.") && !pagesource.Contains("Sorry, that page does not exist") && !pagesource.Contains("User has been suspended"))
                {
                    int length = pagesource.IndexOf("</id>");
                    id = pagesource.Substring(pagesource.IndexOf("<id>"), length - pagesource.IndexOf("<id>")).Replace("<id>", "");
                    user_id = id;
                    GetStatus = "No Error";
                }
                else if (pagesource.Contains("Rate limit exceeded. Clients may not make more than 150 requests per hour."))
                {
                    GetStatus = "Rate limit exceeded";
                }
                else if (pagesource.Contains("Sorry, that page does not exist"))
                {
                    GetStatus = "Sorry, that page does not exist";
                }
                else if (pagesource.Contains("User has been suspended"))
                {
                    GetStatus = "User has been suspended";
                }
            }
            catch (Exception ex)
            {
                Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> GetUserIDFromUsername() -- " + username + " --> " + ex.Message, Globals.Path_TwitterDataScrapper);
                Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> GetUserIDFromUsername() -- " + username + " --> " + ex.Message, Globals.Path_TwtErrorLogs);
                GetStatus = "Error";
            }
            Status = GetStatus;
            return user_id;
        }
コード例 #2
0
        public static string GetUserIDFromUsername_New(string username, out string Status, ref GlobusHttpHelper HttpHelper)
        {
            string GetStatus = string.Empty;

            clsDBQueryManager DB = new clsDBQueryManager();
            DataSet ds = DB.GetUserId(username);
            string user_id = string.Empty;

            try
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dataRow in ds.Tables["tb_UsernameDetails"].Rows)
                    {
                        user_id = dataRow.ItemArray[0].ToString();
                        Status = "No Error";
                        return user_id;
                    }
                }
            }
            catch { };

            try
            {
                string id = string.Empty;
                string pagesource = string.Empty;

                pagesource = HttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + username), "", "");

                if (!pagesource.Contains("Rate limit exceeded. Clients may not make more than 150 requests per hour.") && !pagesource.Contains("Sorry, that page does not exist") && !pagesource.Contains("User has been suspended"))
                {
                   // pagesource = HttpHelper.getHtmlfromUrl(new Uri("https://twitter.com/" + username), "", "");

                    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();
                        user_id = end.Trim();
                    }
                    catch
                    {
                    }

                    if (string.IsNullOrEmpty(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("\"", "");
                            user_id = end.Trim();
                        }
                        catch
                        {
                        }
                    }

                    if (string.IsNullOrEmpty(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);
                            user_id = end.Replace("\"", "");
                        }
                        catch
                        {
                        }
                    }
                }
                else if (pagesource.Contains("Rate limit exceeded. Clients may not make more than 150 requests per hour."))
                {
                    GetStatus = "Rate limit exceeded";
                }
                else if (pagesource.Contains("Sorry, that page does not exist"))
                {
                    GetStatus = "Sorry, that page does not exist";
                }
                else if (pagesource.Contains("User has been suspended"))
                {
                    GetStatus = "User has been suspended";
                }
            }
            catch (Exception ex)
            {
                Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine(DateTime.Now + " --> Error --> GetUserIDFromUsername() -- " + username + " --> " + ex.Message, Globals.Path_TwitterDataScrapper);
                Globussoft.GlobusFileHelper.AppendStringToTextfileNewLine("Error --> GetUserIDFromUsername() -- " + username + " --> " + ex.Message, Globals.Path_TwtErrorLogs);
                GetStatus = "Error";
            }
            Status = "No Error";
            return user_id;
        }