Parsi Coders
سورس بدست اوردن عکس اواتار یوزر در تویتر - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Software Development Programming (http://parsicoders.com/forumdisplay.php?fid=37)
+--- انجمن: C# Programming (http://parsicoders.com/forumdisplay.php?fid=55)
+--- موضوع: سورس بدست اوردن عکس اواتار یوزر در تویتر (/showthread.php?tid=1399)



سورس بدست اوردن عکس اواتار یوزر در تویتر - Amin_Mansouri - 12-30-2011

کد:
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;
            }
}