0

My requirement is to display user photos using facebook API. I can do this successfully. But the problem is this, I cannot retrieve the photos of a user without them logging in. Client doesn't want the user to log in everytime their photos should be displayed. Is this possible?

One solution that I come up with is to generate an access token at developers.facebook.com but the problem with this solution is that users should have prior knowledge in facebook API before they can generate access token and they don't want this. What my client wants is for users to log in ONCE in the app. And after that, retrieve their photos everytime they access the app. How can I do this? Thanks!!

Redis1001
  • 157
  • 15
  • Refer this questions and its answer http://stackoverflow.com/questions/18037926/get-all-photos-of-a-page-using-facebook-api – Sasikumar Sep 15 '16 at 05:58
  • Hello, thank you very much for the answer! But as mentioned above, this method requires basic knowledge of facebook API. The client wants to retrieve all the photos just by logging in once. Future requests should be able to retrieve photos without logging in. Is this possible? Thanks! – Redis1001 Sep 15 '16 at 06:07
  • see my answer. although, if you just want to access the photos "everytime they access the app", you don´t even need an extended token. – andyrandy Sep 15 '16 at 06:30

2 Answers2

0

In order to get user photos (no matter if they are public or not), you MUST authorize that specific user with the user_photos permission. You can store the User Token for future calls, and you can extend the User Token to be valid for 60 days. There is no User Token that is valid forever.

More information about Tokens:

Btw, here´s a good login process, if that is the problem: http://www.devils-heaven.com/facebook-javascript-sdk-login/

How to login in general is explained very well in the docs too: https://developers.facebook.com/docs/facebook-login/

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • Thank you! I can do this now. However, the problem with my previous post is still there. With your answer, I was able to create login very well and retrieve the photos (Thank you for this). But as per the clients requirements, They want to retrieve the photos by just logging in ONCE (meaning if they log out, i should still be able to retrieve the photos). In the current implementation using the documentations above, if the user logs out and I try to access the photos, there is an error produced by facebook that "user is not logged in". Is there any workaround for this? Thanks! – Redis1001 Sep 15 '16 at 06:48
  • that´s why i mentioned the extended user token. you can even get the photos while the user is offline. – andyrandy Sep 15 '16 at 07:14
  • I was successful creating a long-live token that expires in 60 days but still. If I log out, session is already finished and error persists – Redis1001 Sep 15 '16 at 09:05
  • debug the token and make sure it´s really valid and extended and includes the user_photos permission: https://developers.facebook.com/tools/debug/accesstoken/ – andyrandy Sep 15 '16 at 09:24
  • and make sure you use that token. you may want to include your code for the api call in your question. – andyrandy Sep 15 '16 at 09:25
  • Got it! the problem was I am not using the new token.. Thank you very much! This is now already ok. – Redis1001 Sep 16 '16 at 00:30
0

Thank you for all the answers. I finally managed to solve the issue. as discussed by luschn, the proper workflow should be: 1. Login using facebook API 2. Using the app-id and access token generated, make a call to facebook API to extend the access token using this URL:

https://graph.facebook.com/oauth/access_token?             
    client_id=APP_ID&
    client_secret=APP_SECRET&
    grant_type=fb_exchange_token&
    fb_exchange_token=EXISTING_ACCESS_TOKEN 
  1. This would return new long-live facebook API access token.

Thank you!

Redis1001
  • 157
  • 15
  • 1
    why accept that answer? it just repeats part of my answer and is not even about the real question (getting user photos without login), but only about extending a token - which is included in my answer as a link to the official docs. it´s not nice to create your own answer after someone else helped you and accept your own one... ;) – andyrandy May 25 '17 at 08:04