从Codeplex使用facebook c#sdk获取用户个人资料图片 [英] getting user profile picture using facebook c# sdk from codeplex

查看:47
本文介绍了从Codeplex使用facebook c#sdk获取用户个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Codeplex使用Facebook C#sdk,并尝试下载用户的个人资料图片.

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

我知道我可以从:

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

,但是此URL随后将发布到带有实际图片的第二个URL.我如何获得第二个URL?在stackoverflow上有一篇关于解析json的文章,我该怎么做?

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;

推荐答案

您可以让浏览器使用图表API网址-graph.facebook.com/UID/picture?type=large或使用类似的方法来获取图像下面的方法来获取缓存的URL

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;
    }

这篇关于从Codeplex使用facebook c#sdk获取用户个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆