Cannot get no. of photos in a Facebook Album
I am listing the photo albums in my fb account using facebook-c#-sdk 5.0.25
var fb = new FacebookClient();
fb.AccessToken = facebookOAuthResult.AccessToken;
IDictionary<string, object> albums = fb.Get("me/albums") as IDictionary<string, object>;
dynamic albumList = albums["data"];
foreach (dynamic albumInfo in albumList)
{
strAlbid = albumInfo.id;
strAlbName = albumInfo.name;
strAlbDesc = albumInfo.description;
strAlbCnt = albumInfo.count;
strAlbInfo = albumInfo.link;
}
But I cannot get no. of photos in an album because albumInfo.count 开发者_高级运维is not returning any values.
It's difficult to tell from the snippet you've posted, but it appears as though you are attempting to cast the Count as a string (from the variable name strAlbCnt).
Count is a JSON integer - the official documentation claims it is a string, but that is, like many other things on the documentation, not accurate. Check this public example of an album to see what I mean:
"name": "Happy Lunar New Year 2011",
"link": "http://www.facebook.com/album.php?aid=324257&id=20531316728",
"cover_photo": "10150146072661729",
"count": 79,
"type": "normal",
Note that cover_photo is a string despite being numeric, but Count doesn't have the quotes around it, making it a JSON integer.
I can't say for sure this is the cause of your problem, but I have had similar problems coming from dynamic objects before so it's something I instantly suspect.
Not sure if this is the same issue you were encountering, but I had something akin to this:
int albumCount == Data.count;
This would throw a conversion exception because the count field is actually long. So this worked:
long albumCount == Data.count;
精彩评论