Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting user profile picture using facebook c# sdk from codeplex

I am using facebook C# sdk from codeplex and trying to download user's profile picture.

I know I can get this from:

http://graph.facebook.com/UID/picture?type=large

but this URL then posts to a second url with the actual picture. How do I get the second URL? There is a post on stackoverflow that talks about parsing json, how do I do this?

            var app = new FacebookApp();
            var me = (IDictionary<string, object>)app.Get("me");
            string firstName = (string)me["first_name"];
            string lastName = (string)me["last_name"];
            string gender = (string)me["gender"];
            string email = (string)me["email"];
            long facebook_ID = app.UserId;
like image 624
Bruce Avatar asked Feb 01 '11 05:02

Bruce


1 Answers

You could let the browser get the image for you using the graph api url - graph.facebook.com/UID/picture?type=large or use something like the method below to get the cached url

    public static string GetPictureUrl(string faceBookId)
    {
        WebResponse response = null;
        string pictureUrl = string.Empty;
        try
        {
            WebRequest request = WebRequest.Create(string.Format("https://graph.facebook.com/{0}/picture", faceBookId));
            response = request.GetResponse();
            pictureUrl = response.ResponseUri.ToString();
        }
        catch (Exception ex)
        {
            //? handle
        }
        finally
        {
            if (response != null) response.Close();
        }
        return pictureUrl;
    }
like image 120
ak7 Avatar answered Oct 16 '22 08:10

ak7