0

So I got a website where I make the user log-in into the App, and he/she would be able to access all their photos within my page and edit them.

The way I get the albums is this:

FB.api(
  "/me/albums",
     function (response) {
        if (response && !response.error) {
          ...
        }
     }
);

Then after getting the list of album IDs, I iterate through them to get their respective photos by doing:

FB.api(
  "/"+albumId+"/photos",
     function (response) {
        if (response && !response.error) {
          ...
        }
     }
);

This would return an array of objects containing the image IDs.

I thought it would be by using FB.api("/imageId", function(){}) but that returns the same image object with the id.

I want to get the image source/full path so I could add them inside an HTML IMG tag. But I'm still having problems with it.

I saw that there was some way of doing it by getting a "JSON" from this URL:

http://graph.facebook.com/"+photoId

But that throws me a authentication error for example if I try to get it using AJAX (might be because ajax doesn't contain the authentication that FB object does)

How can I get that result ?

Thanks in advance.

msqar
  • 2,940
  • 5
  • 44
  • 90
  • You need to ask for the fields you want, see http://stackoverflow.com/a/32585470/1427878 – CBroe Aug 09 '16 at 07:34
  • But i would like to get the URL for a specific photo ID, that looks like it returns what i already have... if i sned user_photos for field, it will return all the photo IDs, right? – msqar Aug 09 '16 at 13:00
  • _“if i sned user_photos for field”_ – what? And what information are you really looking for – the URL to the photo on Facebook, so that users can view it there? The URL of the image ion Facebook’s CDN, so that you can use it in an `img` element on your site? Or …? – CBroe Aug 09 '16 at 13:10
  • sorry typo error, i meant to say, if i "send". I currently have all the users albums and photos with their IDs. I would like to find a way to display those images in my website, is there any way to get the absolute path to the image? – msqar Aug 09 '16 at 13:11
  • Have you checked the documentation already for which fields are available for Photo objects? https://developers.facebook.com/docs/graph-api/reference/photo – CBroe Aug 09 '16 at 13:12
  • You were totally right, yea. I found a way based on the documentation. I had to add an extra parameter for fields as an object { fields : "..." } and that seemed to work fine :) thanks. – msqar Aug 09 '16 at 13:17

1 Answers1

0

So after getting some documentation links from @CBroe, I found that by doing this

FB.api(
    "/"+photoId, {"fields" : "images"},
    function (response) {
         if (response && !response.error) {
             console.log(response)
         }
    }
);

By sending the field "images", it would return all the absolute paths to the different sizes of that specific image.

If you want a 100x100px thumbnail, you can pass "picture" as the field.

msqar
  • 2,940
  • 5
  • 44
  • 90