Building Twitter profile image url with Twitter user id

前端 未结 10 1693
日久生厌
日久生厌 2020-12-04 18:06

Is there any way of building a profile image url with user id or screen name? I store user ids in database but i don\'t want to store profile image url.

edit

10条回答
  •  日久生厌
    2020-12-04 18:34

    I found such a solution with C#:

        public string Text_toTextFinder(string text, string Fromhere, string Here)
        {
            int start = text.IndexOf(Fromhere) + Fromhere.Length;
            int finish = text.IndexOf(Here, start);
            return text.Substring(start, finish - start);
        }
        string getPhotoURL(string UserName, string size ="x96")
        {
            using (WebClient client = new WebClient())
            {
                client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
                string htmlCode = client.DownloadString("https://twitter.com/" + UserName);
                return Text_toTextFinder(Text_toTextFinder(htmlCode, "", ""), "src=\"", "\"").Replace("normal",size);
            }
        }
    

    For use:

    MessageBox.Show(getPhotoURL("screen_name")); //size = 96x96
    MessageBox.Show(getPhotoURL("screen_name","normal"));
    MessageBox.Show(getPhotoURL("screen_name","200x200"));
    MessageBox.Show(getPhotoURL("screen_name","400x400"));
    

提交回复
热议问题