如果我收到带有“/ me / home”或“XXXX / feed”的所有条目,则每个条目都有一个“from”数组,其中ID和Name为字段。但没有画面。
如何获取所有参赛作品的图片?我不想使用for循环,因为我想直接绑定(WPF)从“/ me / home”接收的数据到ListBox。
答案 0 :(得分:0)
基本上你必须得到照片,你必须传递ID然后得到图片
对不良缩进感到抱歉
这里是代码
result = app.Get("/me/feed");
string id = post.from.id;
foreach (dynamic post in result.data)
{
if (id != tempId)
{
yourControl = getUrlImage("https://graph.facebook.com/" + id + "/picture");
}
}
private Image getUrlImage(string url)
{
WebResponse result = null;
Image rImage = null;
try
{
WebRequest request = WebRequest.Create(url);
result = request.GetResponse();
Stream stream = result.GetResponseStream();
BinaryReader br = new BinaryReader(stream);
byte[] rBytes = br.ReadBytes(1000000);
br.Close();
result.Close();
MemoryStream imageStream = new MemoryStream(rBytes, 0, rBytes.Length);
imageStream.Write(rBytes, 0, rBytes.Length);
rImage = Image.FromStream(imageStream, true);
imageStream.Close();
}
catch (Exception c)
{
MessageBox.Show(c.Message);
}
finally
{
if (result != null) result.Close();
}
return rImage;
}