Getting all the photos in a user's profile using Facebook SDK on android [duplicate]

戏子无情 提交于 2020-01-07 07:58:07

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/31666627/getting-all-the-photos-in-a-users-profile-using-facebook-sdk-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!