使用Facebook C#SDK的Facebook相册图片 [英] Facebook Album Picture using Facebook C# SDK

查看:72
本文介绍了使用Facebook C#SDK的Facebook相册图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正准备在Silverlight应用程序中使用facebook C#SDK从Facebook获取相册图片,

I'm tring to get an album picture from facebook using the facebook C# SDK within Silverlight app with the following code:

        FacebookClient client = new FacebookClient(this.Profile.AccessToken);
        client.GetAsync(string.Format("/{0}/picture?type=small", this.ID));
        client.GetCompleted += (s, e) =>
        {
            dynamic result = e;
        };

其中this.ID是相册的ID,但出现此错误:解析值时遇到意外字符:.第1行,位置1.从JsonSerializer中的DeserializeObject方法中获得.问题在于,facebook不会使用imge uri或类似形式返回json数据,但实际上它们会以二进制数据形式返回图像本身.有人知道我如何处理这个结果,或者只是让Uri知道图像吗?我可以使用以下代码解决此问题:

Where this.ID is the ID of the album, but I get this error: Unexpected character encountered while parsing value: �. Line 1, position 1. from the DeserializeObject method in the JsonSerializer. The problem is that facebook does'n return json data with the imge uri or something like this, but they actually return the image itself in a binary data. Anybody has any idea how I can handle this result or just get Uri to the image? I have a workaround for this using this code:

        var request = WebRequest.Create(string.Format("https://graph.facebook.com/{0}/picture?access_token={1}", this.ID, this.Profile.AccessToken));
        request.BeginGetResponse(ar =>
        {
            using (var response = ((WebRequest)ar.AsyncState).EndGetResponse(ar))
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    this.Picture = new BitmapImage(new Uri(response.ResponseUri.AbsoluteUri));
                }
                );
            }
        }, request);

但是我真的只想使用Facebook C#SDK来获取数据.

But I really wanted to use only Facebook C# SDK for getting the data.

这是我要使用的解决方案:

Here is the solution that I'm going to use:

        FacebookClient client = new FacebookClient(this.Profile.AccessToken);
        client.QueryAsync(String.Format("SELECT src_small, src_big, src FROM photo WHERE pid IN (SELECT cover_pid FROM album WHERE object_id={0})", this.ID));
        client.GetCompleted += (s, e) =>
        {
            dynamic result = e.GetResultData();

            Deployment.Current.Dispatcher.BeginInvoke(() => this.Picture = result[0].src_small);
        };

推荐答案

我认为我找到了可接受的解决方案.我将只使用FQL而不是Graph API.这样就可以了:

I think I found an acceptable solution for my problem. I'll just use FQL instead of Graph API. This will do the job:

        FacebookClient client = new FacebookClient(this.Profile.AccessToken);
        client.QueryAsync(String.Format("SELECT src_small, src_big, src FROM photo WHERE pid IN (SELECT cover_pid FROM album WHERE object_id={0})", this.ID));
        client.GetCompleted += (s, e) =>
        {
            dynamic result = e.GetResultData();

            Deployment.Current.Dispatcher.BeginInvoke(() => this.Picture = result[0].src_small);
        };

这篇关于使用Facebook C#SDK的Facebook相册图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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