-1

I am making an application in which I want to fetch the profile pictures of a facebook user. I tried to fetch the albums from facebook but I am getting null response from the facebook server. I have tried it with multiple users but its not working.Can anyone help me?

here is my code:

mAsyncRunner.request(fbuserid+"/albums", new RequestListener() 
{
    @Override
    public void onComplete(String response, Object state)
    {
        try
        {
            JSONObject albumjson = Util.parseJson(response);
            JSONArray albums = albumjson.getJSONArray("data");
            for (int i =0; i < albums.length(); i++)
            {
                JSONObject album = albums.getJSONObject(i);
                String album_name = album.getString("name");
                String album_id = album.getString("id");

                System.out.println("albumname  "+album_name +album_id);
            }
        } 
        catch (JSONException e) 
        {
            e.printStackTrace();
        } 
    }
    @Override
    public void onIOException(IOException e, Object state)
    {
    }

    @Override
    public void onFileNotFoundException(FileNotFoundException e,Object state)
    {
    }

    @Override
    public void onMalformedURLException(MalformedURLException e,Object state) 
    {
    }

    @Override
    public void onFacebookError(FacebookError e, Object state) 
    {
    }
});
Phoenix
  • 238
  • 2
  • 12

1 Answers1

1

You should try to get by below code:

If you have album id then

new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{album-id}/photos",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();

And If it's for a particular person then

new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/me/photos",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();

For this you need to set Permissions

1) Any valid access token if the photos are public.

2) A user access token user_photos permission to retrieve any photos that the session user has uploaded that are not public.

Reference : https://developers.facebook.com/docs/graph-api/reference/v2.0/album/photos

Hope it will help.

For detailed explanation please refer below link :

iOS : Facebook Album Photos Picker

Community
  • 1
  • 1
KishuDroid
  • 5,411
  • 4
  • 30
  • 47
  • I am not getting the albums.I am always getting null response.Then how can I get album id? – Phoenix Oct 29 '15 at 10:02
  • Try to follow the steps which are given in link. Check there you are getting album or not? – KishuDroid Oct 29 '15 at 10:04
  • Thanks..I am getting the albums only for my developer account using my code not for other user. Is that any issue regarding my code? – Phoenix Oct 29 '15 at 11:19
  • No . Your code will work after publishing your app. You can add user in facebook developer account for testing. – KishuDroid Oct 29 '15 at 11:21