Question

i am using facebook4j to load home posts facebook.getHome() and i am getting the profile image and the post image as follows:

facebook4j.User fromUser = facebook.getUser(fbHomePost.getFrom().getId(), 
new Reading().fields("picture"));
if (fromUser.getPicture() != null)                      
  facebookUserPostDto.setProfileImage(fromUser.getPicture().getURL().toURI().toString());
if (fbHomePost.getPicture() != null)
  facebookUserPostDto.setImageLocation(fbHomePost.getPicture().toURI().toString());

all is working well, but the image i am getting from the URLs are small and have low resolution. any idea how to get the "large" images from facebook using facebook4j API? facebook can provide different image sizes API Reference › Graph API › Pictures

thanks

Was it helpful?

Solution 2

ok i got a reply from the facebook4j google group on how to go this retrieve different image size from my facebook posts

Sameeh Harfoush

Brate

OTHER TIPS

OK first you have to add user_photos to your scope and make sure you are using a valid acces token NOT a Graph API Explorer Token

OAuthService service = new ServiceBuilder()
                                      .provider(FacebookApi.class)
                                      .apiKey(apiKey)
                                      .apiSecret(apiSecret)
                                      .callback("xxxx")
                                      .scope("publish_actions,user_photos ")
                                      .build();

then try this : (tested)

for(Post p : feed){
        System.out.println("********************");
        String type = p.getType();
        System.out.println("type :"+type);
        String idPicVid = p.getObjectId();
        if(type.matches("photo")){
           System.out.println("idPicVid "+idPicVid);
                try{
                    Photo pic = facebook.getPhoto(idPicVid);
                    System.out.println(pic.toString());
                    System.out.println("source "+pic.getSource());
                    System.out.println("picture "+pic.getPicture());
                }catch (Exception e) {
                    e.printStackTrace();
                }
        }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top