BamsBamx BamsBamx - 1 month ago 12
Android Question

Android - Get profile cover picture from Facebook

I am using Facebook SDK and Parse SDK and I want to retrieve the profile cover picture.

I am doing the following:

new Request(
ParseFacebookUtils.getSession(),
"/me?fields=cover",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
Log.wtf("TAG",
response.toString());
}
}).executeAsync();


But I am not able to get the proper response since it says I need an access token (the user has already been logged in).

{Response:
responseCode: 400,
graphObject: null,
error: {
HttpStatus: 400,
errorCode: 2500,
errorType: OAuthException,
errorMessage: An active access token must be used to query information about the current user.
},
isFromCache:false
}


Is there any fix for this available?

Answer

After spending A LOT of hours searching for the answer, I finally got it !!!

The Android SDK for Facebook docs, are too useless.

To solve this problem we just need to set the Graph Path in the second param and a Bundle with fields as third param. Example:

Bundle params = new Bundle();
            params.putString("fields", "cover");
            new Request(ParseFacebookUtils.getSession(),
                    "me",
                    params,
                    HttpMethod.GET,
                    new Request.Callback() {
                        @Override
                        public void onCompleted(Response response) {
                            //code...
                        }
                    }).executeAsync();

Then we can parse the response object returned in onCompleted as JSON with

response.getGraphObject().getInnerJsonObject();
//or
response.getGraphObject().getProperty("cover");

Source: New Facebook SDK and OAuthException in Graphpath requests thanks to @Jesse Chen