Strange JSON error when trying to fetch album's photos from Facebook

150 views Asked by At

I am using Facebook SDK to load the photos from a specific album like this:

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();

}

I receive a strange error when I try to access name property of the photo (which I am sure it exists):

'System.Collections.Generic.KeyValuePair<string,object>' does not contain a definition for 'name'

Do you know why?

1

There are 1 answers

0
Cristian Boariu On BEST ANSWER

Solution found:

Instead of: foreach (dynamic imageInfo in albumsPhotos) I had to use foreach (dynamic imageInfo in albumsPhotos.data) to be able to access the properties of the Object.