15

I am new to Facebook API but I have to get all photos from a Facebook page. I managed to get a graph api query that returns all pictures of only the first ever created album on the page which is the profile picture album. For example:

https://graph.facebook.com/227843870675663/photos

But I need to do the same for all other existing albums in the page. Any pointers are really appreciated.

lbrahim
  • 3,710
  • 12
  • 57
  • 95

2 Answers2

37

Try this and let me know how it goes for you. I've successfully pulled all photos from a Facebook page.

  1. Ensure that you are an Admin of the Facebook Page.

  2. Go to: http://developers.facebook.com/tools/explorer

  3. In the API Navigator, you can access /me to bring up the basic information of yourself.

  4. Try typing in /me/accounts to see if you can see anything. It should give you an error.

  5. You need to enable certain permissions to make this Graph query. Choose the relevant permissions in the right sidebar. According to this doc you need the pages_show_list and pages_read_engagement permissions for this query.

  6. Click on "Get Access Token" which will give you a new token with the updated permissions. You may get a popup window where you have to confirm which page(s) you would like this access token to be able to see.

  7. Now try /me/accounts again. You should see a list of pages that you enabled access for, inside the viewing window.

  8. Find the Facebook Page you want to query, and click on the "id" field. This ID is needed for making any queries related to this page.

  9. Next, on the left window, you can see "Node: " and a + sign. Click on the + sign to see what options you have.

  10. Click on the + sign and scroll down to "connections" and select "Albums"

  11. The child-level, select "Photos"

  12. The "Photos" child-level, select "source"

  13. Now click "Submit" on the right hand side.

    If the above doesn't work, you can try copying the following URL into the API explorer:

    YOUR_PAGE_ID/?fields=albums.fields(photos.fields(source))
    

    You will see a JSON returned with the URL of some/all of the photos in your selected Facebook Page.

  14. Click "Get Code" and it will show you the Javascript or raw URL used to access this information.

    The "cURL" tab will show the URL which will look something like this:

    https://graph.facebook.com/v15.0/YOUR_PAGE_ID?fields=albums.fields(photos.fields(source))&access_token=YOUR_ACCESS_TOKEN_HERE
    

    You can copy that URL and plug it into your browser. You should see a JSON of all your photos, and each photo's corresponding URL on Facebook's CDN.

Getting photos posted to the feed, not just photo albums

To do that, you need to run a slightly different query:

https://graph.facebook.com/v15.0/YOUR_PAGE_ID/feed?fields=attachments

Getting high resolution imagery

Many of the image URLs provided by the queries above will only provide resolutions up to 720px. If you want higher resolution images, then you need to find the target.id for each subattachment, and perform a separate graph query for each image to obtain the other resolutions. It looks like this:

https://graph.facebook.com/v15.0/YOUR_IMAGE_ID?fields=images

Watch out for expiring tokens

The token generated above will only work for approximately 1-2 hours. If you want a longer lasting token, follow the steps in this post here.

Simon East
  • 55,742
  • 17
  • 139
  • 133
Max
  • 982
  • 10
  • 21
  • 2
    Thanks! This is what I was looking for. To directly access the photos of a page. – lbrahim Aug 14 '13 at 08:11
  • Let me know how it goes. The /accounts is basically the Pages you are admin of. – Max Aug 14 '13 at 10:22
  • question, is the access token solely inherit by the user which got the follow this setup to get the access token? and what will happen if the user is no longer an admin? is there a way to put it under application to access the facebook fan page album? – zearth Feb 04 '14 at 13:05
  • I think the access token is for that moment of access. FB doesn't renew tokens or something like that. The URL persists tho, so far I've seen. Haven't touched this for quite sometime now. – Max Mar 31 '14 at 21:30
  • 1
    @Max's answer is correct, but if we want get ALL photos, think, should some change url to: `/me?fields=albums.fields(photos.limit(99999).fields(id))&limit=99999` – Yura Shinkarev Aug 26 '14 at 21:31
  • 16. Really does it, I could get all of my 231 photos, thanks a lot. – Borzh Mar 04 '16 at 21:46
  • @Borzh i get all photos in screen, and then i get code, then how i can use that code in my website for displaying pic? – Hamza Zafeer Oct 17 '16 at 12:46
  • @HamzaZafeer Sorry I am not a web programmer, you should ask this as a new question, so you could get help. – Borzh Oct 18 '16 at 16:52
  • @HamzaZafeer in Step 16, all you need to use is the URL that is Facebook's CDN. You should see something like "https://....fbcdn.net/...../xxxx.jpg" for each image. – Max Oct 18 '16 at 21:37
  • 1
    What if I'm not an admin of the page? But only want to access public photos – Isomorphic Jul 27 '17 at 19:06
  • As Isomorphic asked, is it possible to get public photos of a page when you're not the admin? – Simon East Jan 12 '23 at 06:50
  • From my research, I think it is theoretically possible to query public pages without being an admin, however you need to submit an application to Facebook for the `pages_read_engagement` permission or "Page Public Content Access (PPCA)" feature ([as per this page](https://developers.facebook.com/docs/graph-api/reference/page/)). This is long and labor-intensive process, be aware. I think they've cracked down on it since various data breaches. – Simon East Jan 13 '23 at 15:41
  • hmm, the steps still work after so long? wow. – Max Jan 17 '23 at 08:56
  • I'm admin of the page and able to retrieve the posts from the feed. I think I correctly requested pages_read_engagement & pages_read_user_content but I don't know how to be sure. When I try to get the list of albums I get a `Missing Permissions` error. Any idea? `{"error": { "message": "(#200) Missing Permissions", "type": "OAuthException", "code": 200 }}` – Maxbester May 06 '23 at 09:24
6

When you get your Facebook user, you can:

  • get the list of all its albums
  • get the user's profile picture
  • get the photos the user (or friend) is tagged in

They respectively need those permissions:

  • user_photos or friends_photos
  • not needed
  • user_photos or friends_photos

UPDATE:

If you want to get those information from a Facebook page:

  • Photos - The Page's uploaded photos.
  • Albums - The photo albums the Page has uploaded.

Permissions are: any valid access_token or user access_token

glautrou
  • 3,140
  • 2
  • 29
  • 34
  • 1
    Thanks for the help. But my problem revolves around a **Facebook Page** not **Facebook Users**. AFAIU, pages are open and I will not need any kind of authorization to access it. At least, to get all the photos from that page. For notifications maybe that page have to be liked. Correct me if I am wrong. – lbrahim Aug 04 '13 at 00:20
  • Thanks again. But I replaced the id you provided with one of mine above and the result is the same. I only get all pics from the **Page's first album only**. I need all photos from that page. [link](https://developers.facebook.com/tools/explorer/?method=GET&path=227843870675663%2Fphotos) – lbrahim Aug 04 '13 at 13:24
  • Get the list of all albums and for each album the list of all photos and it will work. – glautrou Aug 04 '13 at 16:19
  • Alright! Thanks. I suppose that is a way also. But I was wondering if there was any API to directly pull out all photos in an array. – lbrahim Aug 04 '13 at 19:13
  • No :) But the logic in the API is correct, that allow to differentiate images stored in albums or not. – glautrou Aug 04 '13 at 19:53
  • How to get Picture URLs? – Shajeel Afzal Sep 14 '16 at 04:43