Search code examples
facebookfacebook-access-token

Can i load the private photos with my webapp from facebook users?


I have a website and use the login using facebook. I want to do the following:

User comes to my web site - login with facebook - I read his facebook data and photography permits

For example:

{
    "id": "1"
    "name": "John English"
    "first_name": "John",
    "last_name": "English"
    "link": "https://www.facebook.com/johnenglish"
    "username": "johnenglish"
    "gender": "male"
    "locale": "en_US"
     ....
}

and

{
    "id": "2"
    "name": "John English2"
    "first_name": "John",
    "last_name": "English2"
    "link": "https://www.facebook.com/johnenglish2"
    "username": "johnenglish2"
    "gender": "male"
    "locale": "en_US"
     ....
}

Both users have a private photo. Can I load the private photos from user (id: 2) with my web application using javascript? Can you give me the example?

I've tried this:

FB.getLoginStatus(function(response) {
                if (response.status === 'connected') {
                    var uid = response.authResponse.userID;
                    var accessToken = response.authResponse.accessToken;

                    FB.api('/USER-ID(USER ID 2)/photos?access_token=' + accessToken, function(response) {

            //A user access token is required to request this resource.


                    });



                } else if (response.status === 'not_authorized') {

                } else {
                }
            });

Error: A user access token is required to request this resource.


Solution

  • Have you requested the right permissions when you gained your access token? I don't know how to do it in JS, but you have to tell facebook, that you want you get access to the photos. As I do not work with JS, I request my access token via an URL (see Point 1 here: https://developers.facebook.com/docs/authentication/devices/). In the parameter "scope" you can add the permissions you want to have ( https://developers.facebook.com/docs/authentication/permissions/). Here, you add "&scope=user_photos" (without quotation marks) to the URL.