我使用Facebook SDK加载特定相册中的照片,如下所示:
private void LoadAlbum(String albumId)
{
var fb = new FacebookWebClient("token_id");
dynamic albumsPhotos = fb.Get(albumId + "/photos");
List<FacebookImageVo> listOfImages = new List<FacebookImageVo>();
foreach (dynamic imageInfo in albumsPhotos)
{
FacebookImageVo facebookImage = new FacebookImageVo();
if (imageInfo.name != null)
{
facebookImage.Name = imageInfo.name;
}
facebookImage.Id = imageInfo.id;
facebookImage.Source = imageInfo.source;
facebookImage.Picture = imageInfo.picture;
}
rptImages.DataSource = listOfImages;
rptImages.DataBind();
}
当我尝试访问照片的name
属性时(I am sure it exists),我收到一个奇怪的错误:
'System.Collections.Generic.KeyValuePair<string,object>' does not contain a definition for 'name'
你知道为什么吗?
答案 0 :(得分:0)
找到解决方案:
而不是:foreach (dynamic imageInfo in albumsPhotos)
我必须使用foreach (dynamic imageInfo in albumsPhotos.data)
才能访问对象的属性。