Reputation: 31
All, I am a beginner in Facebook programming. My test project is a simple website which displays Facebook account information (only name and id) and the list of albums of that Facebook account. The problem is, after authentication, I can get the profile data, but I cannot get the album list. Here is code to get the profile information:
[FacebookAuthorize(LoginUrl = "~/Account/Login")]
public ActionResult Profile()
{
var fbWebContext = FacebookWebContext.Current;
if (fbWebContext.IsAuthorized())
{
try
{
var fb = new FacebookWebClient(fbWebContext);
var token = fb.AccessToken;
dynamic me = fb.Get("/me");
ViewBag.Name = me.name;
ViewBag.Id = me.id;
ViewBag.AccessToken = token;
}
catch (Exception ex)
{
{
fbWebContext.DeleteAuthCookie();
Session.Clear();
}
return RedirectToAction("Login", "Account");
}
}
return View();
}
and here is code to get the album list
[FacebookAuthorize(LoginUrl = "~/Account/Login")]
public ActionResult Album()
{
var fb = new FacebookWebClient(FacebookWebContext.Current);
IDictionary<string, object> albums = fb.Get("me/albums") as IDictionary<string, object>;
dynamic albumList = albums["data"];
foreach (dynamic albumInfo in albumList)
{
if (ViewBag.Albums == null)
ViewBag.Albums = new List<string>();
ViewBag.Albums.Add(albumInfo.id);
}
return View();
}
in above code, the item count of albumList always = 0. Could you please help me to resolve this issue? A minor note: my test website is a ASP.Net MVC3 web application written in C#.
Edit in response to Andy's answer:
In fact, I set lots of permissions but it still cannot get the album list. Here is code in my OAuth method.
var parameters = new Dictionary<string, object>();
parameters.Add("permissions", "user_about_me,offline_access,user_photos,publish_stream");
dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken(code, parameters);
Note that I did try to replace ""permissions" by "scope" but still failed.
Upvotes: 0
Views: 1598
Reputation: 2303
Have you requested the user_photos
permission? You need to request additional permissions during Authentication if you want to access additional user data.
See this Facebook permissions page for more info.
If you are using the Facebook JavaScript SDK FB.login method then you can simply add the user_photos
permission to the perms option:
FB.login(function(response) {
if (response.session) {
if (response.perms) {
// user is logged in and granted some permissions.
// perms is a comma separated list of granted permissions
} else {
// user is logged in, but did not grant any permissions
}
} else {
// user is not logged in
}
}, {perms:'user_photos'});
Hope this helps.
Upvotes: 1