0

I am trying to access a public FB community page and display the images on web page, example-http://www.codeofaninja.com/2011/06/display-facebook-photos-to-your-website.html My site is being developed in java, so I am looking for a core java solution to do something like this.

My site does not prompt for the user to login via Facebook or authenticate. I am simply trying to display all the images from my own album on my website.

I have created an FB app, and then created a community page on which I have my pictures.

I am struggling to I authenticate from the backend code of my with my app or page. My app has user_photos permission and the App Type (Apps->Your APP->Advanced->App type) is Web.

Here are the things I tried using graph API: 1) Get access token

https://graph.facebook.com/oauth/access_token?client_id=ABC&client_secret=XYZ&grant_type=client_credentials

2) Then use access token to get access to the page and its albums, but the above gives me app access_token. As mentioned on Graph API documentation for Page it requires a page acess_token, but I am not understanding how do I get the page_access_token via an app access_token with a backend application.

After Page access token is retrieved I can use the following call to retrieve all photos.

https://graph.facebook.com/PAGE_ID/photos?access_token=<page_access_token>
NRJ
  • 1,064
  • 3
  • 15
  • 32

3 Answers3

1

You can make the following Graph API call To get the page access tokens for all the Pages a particular user admin.

https://graph.facebook.com/user_id/accounts?access_token=<user_acess_token>
Mahesh
  • 31
  • 5
0

the app access token that you're retrieving from

https://graph.facebook.com/oauth/access_token?client_id=ABC&client_secret=XYZ&grant_type=client_credentials

can be used to access the public data on a page - you don't need a specific 'page' access token.

this page https://developers.facebook.com/tools/explorer/ is handy for testing things out - plug in the app access token and the page url to try it out

caitriona
  • 8,569
  • 4
  • 32
  • 36
  • I had already tried it, it returns me a blank data element. Am I missing any other setting in my app? As I mentioned, I already have user_photos permission in my app. – NRJ Oct 03 '12 at 17:30
  • what returns the blank data element? the call to the url for the photos? are the photos definitely publicly available? try querying this link: https://graph.facebook.com/cocacola/photos?access_token=YOUR_ACCESS_TOKEN - it works for me with the access token from an app i created with the default settings – caitriona Oct 04 '12 at 09:06
  • When I get a short lived access token from https://developers.facebook.com/tools/explorer/, I am able to get the album data by querying - `https://graph.facebook.com/ALBUM_ID/photos?access_token=SHORT_LIVED_ACCESS_TOKEN`, but how to get a long lived token? This page didn't help either - [link]https://developers.facebook.com/roadmap/offline-access-removal/#page_access_token – NRJ Oct 14 '12 at 14:47
0

but I am not understanding how do I get the page_access_token via an app access_token with a backend application.

Not at all …

To get a page access token, you have to have a user access token with manage_pages permission first.

(If you get a long-lived user access token, and use that to get the page access token, then the latter will not expire by default.)

CBroe
  • 91,630
  • 14
  • 92
  • 150