2013-04-15 35 views
0

我使用facebook4j加載回家的帖子facebook.getHome()和我得到的資料圖片和帖子相關圖片如下:facebook4j從我的Facebook的職位檢索不同的圖像大小

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()); 

一切工作正常,但圖像我從網址很小,分辨率低。任何想法如何使用facebook4j API從Facebook獲得「大」圖像? Facebook能夠提供不同的圖像大小API Reference › Graph API › Pictures

感謝

+0

沒有人使用過facebook4j嗎? –

+0

我已經整合了facebook4j,但我得到重複的提要。你可以幫我這個:http://stackoverflow.com/questions/16293540/facebook-feed-integration-with-android-app-feeds-getting-duplicated? – YuDroid

回答

0

我從來沒有使用facebook4j,但我會告訴你如何實現這個使用標準的Facebook SDK 3.0爲Android。

在Facebook新的飼料圖對象,你有字段'object_id'。當你得到object_id你可以檢索所有類型的圖像資源。

請求

Request r = new Request(session, "/"+ MyJsonData.getData().get(position).getObject_id(), null,HttpMethod.GET, callback2); 

RequestAsyncTask task = new RequestAsyncTask(r); 
task.execute(); 

回調

Request.Callback callback2 = new Request.Callback() { 
     public void onCompleted(final Response response) { 
        if (response != null) { 
     JSONObject graphResponse = null; 
         try { 
          if(response.getGraphObject().getInnerJSONObject()!=null){ 
    System.out.println("json:" + response); 
    graphResponse = response.getGraphObject().getInnerJSONObject(); 
       } 
         } catch (Exception e) { 
          // TODO: handle exception 
         } 
         try { 

      url = graphResponse.getString("source"); 


          ImageLoader.getInstance().displayImage(url,myImageView); 

     } else { 
       System.out.println("NULL"); 
        } 
       } 
    }; 

我希望它會幫助你

+0

感謝, 我管理的獲取用戶的大輪廓影像,它看起來不錯 URL userPrifilePic = facebook.getPictureURL(fbHomePost.getFrom()的getId(),PictureSize.large。); 但仍然工作在如何獲得體面的分辨率後圖像 –

0

OK首先你要user_photos添加到您的範圍,並確保您使用的是有效的存取權限令牌不是一個圖形API瀏覽器令牌

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

那就試試這個:(測試)

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(); 
       } 
     } 
}