문제

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

도움이 되었습니까?

해결책 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

다른 팁

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();
                }
        }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top