Parsi Coders

نسخه‌ی کامل: سورس بدست اوردن عکس اواتار یوزر در تویتر
شما در حال مشاهده نسخه آرشیو هستید. برای مشاهده نسخه کامل کلیک کنید.
کد:
string getTwitterUserImage(string userUrl)
        {
            try
            {
                // The initial Twitter URL
                string twitterUrl = userUrl;
                HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(twitterUrl);
                myRequest.Method = "GET";
                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                StreamReader myPageSource = new StreamReader(myResponse.GetResponseStream());
                string source = myPageSource.ReadToEnd();
                myResponse.Close();

                // The set of selections that will be
                // used to select the needed part from
                // the HTML source of the user page.
                int selectionA = 0;
                int selectionB = 0;
                int selectionC = 0;

                selectionA = source.IndexOf("<img alt=\"\" border=\"0\" height=\"73\" id=\"profile-image\"");
                selectionB = source.IndexOf("src=", selectionA);
                selectionC = source.IndexOf("valign=\"middle\"", selectionB + 4);

                // Extract the image URL from the source selection.
                string fullUrl = source.Substring(selectionB + 5, selectionC - 7 - selectionB);
                return fullUrl;
            }
            catch (Exception exc)
            {
                return null;
            }
}