-1

I'm able to get profile photo of a user using Facebook SDK 4.0 on android using this -

loginButton = (LoginButton)findViewById(R.id.login_button);
        profile = (ImageView)findViewById(R.id.profile);


        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

                String userId = loginResult.getAccessToken().getUserId();                             

                String imageUrl = String.format("https://graph.facebook.com/%s/picture?type=large", userId);

                Picasso.with(getBaseContext()).load(imageUrl).into(profile);

            }

}

How to go about getting all the photos in a user's profile ? Any help is appreciated.

Gissipi_453
  • 1,250
  • 1
  • 25
  • 61

1 Answers1

0

Firstly Make sure the AccessToken has user_photos permission

Then on the app, call a GraphRequest with a photos{link} field

GraphRequest request = GraphRequest.newMeRequest(
                            AccessToken.getCurrentAccessToken(),
                            new GraphRequest.GraphJSONObjectCallback() {
                                @Override
                                public void onCompleted(
                                        JSONObject object,
                                        GraphResponse response) {
                                    try {
                                        //This contains all the photos with array data>>link 
                                        JSONObject photosobject = object.getJSONObject("photos");




                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
    Bundle parameters = new Bundle();
                    parameters.putString("fields", "id,name,picture,photos{link}");
                    request.setParameters(parameters);
                    request.executeAsync();

Then please refer to the Facebook Graph API tool to test the values you want https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Dphotos%7Blink%7D

Note: also make sure that you have the latest FacebookSDK

Sheychan
  • 2,415
  • 14
  • 32
  • Can you please tell where and how to use this ? – Gissipi_453 Jul 28 '15 at 04:17
  • You use it anywhere whenever you want to do it... the JSONObject is up to you to explore its data – Sheychan Jul 28 '15 at 06:00
  • How do I add the photos in a ListView using this ? Using HashMap, I pass two strings to my ListView adapter. – Gissipi_453 Jul 28 '15 at 06:04
  • 1
    Back to basic: 1. get the Value of the links of photos from that JSONObject into list 2. put the list of the link of the photos in your adapter 3. set the adapter of the listview Though I only answered the question youve made. The population of the listview is beyond this topic already but I am still willing to help yah ;) – Sheychan Jul 28 '15 at 06:08
  • Thanks a lot. Im trying – Gissipi_453 Jul 28 '15 at 06:11
  • Btw the link I gave will really help you on what JSON data it shows give it a look and experiment – Sheychan Jul 28 '15 at 06:16
  • Yes. Thanks for helping. I'm already up trying it. – Gissipi_453 Jul 28 '15 at 06:18