我正在使用以下代码将图片作为附件添加到Fanpage帖子中。
问题1 :如何发布 多张图片(作为多个附件)?
[HttpPost]
public ActionResult PostArticle(FbPostArticle model)
{
var fanpage = _fanpageService.GetById(model.PageId);
if (fanpage == null)
{
return RedirectToAction("Index");
}
var fb = new FacebookClient();
string photoId = "";
try
{
dynamic result;
string url;
if (model.Image != null)
{
if (!IsAllowExtension(model.Image.FileName))
return RedirectToAction("Feed", model.PageId);
var fbUpl = new FacebookMediaObject
{
FileName = model.Image.FileName,
ContentType = model.Image.ContentType
};
var target = new MemoryStream();
model.Image.InputStream.CopyTo(target);
byte[] bytes = target.ToArray();
fbUpl.SetValue(bytes);
url = fanpage.PageId + "/photos";
result = fb.Post(url, new
{
access_token = fanpage.AccessToken,
published = false,
image = fbUpl
});
photoId = result.id;
}
var postContent = new Dictionary<string, object>
{
{"access_token", fanpage.AccessToken},
{"message", model.Message},
};
if (!string.IsNullOrEmpty(photoId))
{
postContent.Add("attached_media[0]", "{\"media_fbid\": " + photoId + "}");
}
url = fanpage.PageId + "/feed";
result = fb.Post(url, postContent);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
return RedirectToAction("Feed", new { id = model.PageId });
}
}
问题2 :如何通过Graph API 获取这些图片? (按照API文档中的说明,我似乎无法获得它。)