简体   繁体   中英

Facebook albums cover photo using latest facebook SDK?

We can fetch facebook photo albums details using garph API {user-id}/albums

      /*make API call*/
        new GraphRequest(
                AccessToken.getCurrentAccessToken(),  //your fb AccessToken
                "/" + AccessToken.getCurrentAccessToken().getUserId() + "/albums",//user id of login user
                null,
                HttpMethod.GET,
                new GraphRequest.Callback() {
                    public void onCompleted(final GraphResponse response) {
                }
        }).executeAsync();

Now i need to get cover photo of those albums and i know using garph API {albums-id}/picture we can do that.like below

            Bundle params = new Bundle();
            params.putString("type", "small"); //You use this to get a pre-specified size of picture.
            params.putBoolean("redirect", false);
            new GraphRequest(
                    AccessToken.getCurrentAccessToken(),
                    "/" + id + "/picture",
                    params,
                    HttpMethod.GET,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {

                    }
            }).executeAsync();

But we need to make a different API call for it.is there any way to get albums cover photo along with albums details ?

and also I'm getting less quality cover photos.

I have tried with all types from here

type : enum{thumbnail,small,album}

You can't get a larger image than album . That's the size you're seeing on the FB album overview page.

To get the data with one call, you have to use the Field API like this:

GET /mashable/albums?fields=id,name,picture.type(album)

Try it yourself

With the Android SDK, the code should be

GraphRequest request = new GraphRequest(
    AccessToken.getCurrentAccessToken(),  //your fb AccessToken
    "/" + AccessToken.getCurrentAccessToken().getUserId() + "/albums",//user id of login user
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(final GraphResponse response) {
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,picture.type(album)");

request.setParameters(parameters);
request.executeAsync();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM