-4

How can you get the list of user photo albums using the Facebook Graph API?

AJ9
  • 1,256
  • 1
  • 17
  • 28

1 Answers1

0

In the OnCreate of the Activity..

    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            AccessToken token =  loginResult.getAccessToken();

            GraphRequest.Callback callback = new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse graphResponse) {
                    //Use the data
                }
            };

            GraphRequest req = GraphRequest.newGraphPathRequest(token, "me/albums",  callback);
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id, name, count");
            req.setParameters(parameters);
            req.executeAsync();


        }

        @Override
        public void onCancel() {
        //User Cancelled
        }

        @Override
        public void onError(FacebookException e) {
            //Handle Error
        }
    });

In your OnClick method:

LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("user_photos"));

You'll also need this:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}
AJ9
  • 1,256
  • 1
  • 17
  • 28