Https://graph.facebook.com/me/albums sometimes returns nothing

I experimented with the Facebook API using the Javascript SDK. Whenever I logged in to Facebook, I can fairly reliably call:

function init() { // Called after loading the Facebook SDK FB.api("/me", function(response) { console.log(response.first_name); // "John" (always works) }); } 

But I also want to get user photo albums (when they click the link), and for some reason this call only works intermittently:

 $(document).ready(function) { $("#get-albums-link").click(function() { var accessToken = "456"; // Just an example FB.api("/me/albums?access_token=" + accessToken, function(response) { console.log(response); // An empty object about 40% of the time }); }); }); 

When this happens, I can open a new tab and make sure that even direct requests return the same empty result (note that although this may be an authorization problem, there is no obvious indication that it exists: it is just an empty JSON object):

 <!-- An HTTPS GET at https://graph.facebook.com/me/albums?access_token=456 --> { "data": [ ] } 
+7
source share
1 answer

As Felipe noted above, the access token can be a problem, since the permission set {"data": []} will not be installed. Try it yourself: https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Falbums

Also, even if it is a valid auth_token, the SDK does not require it, so do not use it. You might end up with something like graph.facebook.com/me/albums?access_token=123423&access_token=981234 (second access token added by the SDK). I personally do not know how the FB.api function is created, but just follow the docs: https://developers.facebook.com/docs/reference/javascript/FB.api/

Let me know if you still have problems.

+1
source

All Articles