2012-12-04 85 views
1

我正在嘗試使用restfb將照片發佈到用戶的頁面時間軸。Facebook:將照片發佈到restfb的時間軸

我的代碼是這樣的:

// Create parameters for the call 
Collection<Parameter> params = new ArrayList<Parameter>(); 
params.add(Parameter.with("message", "My Message")); 
Parameter postParamsArray[] = params.toArray(new Parameter[params.size()]); 
java.net.URL url = new java.net.URL("http://i.istockimg.com/file_thumbview_approve/4739627/2/stock-illustration-4739627-dreidel-game.jpg"); 
FacebookType publishMessageResponse = facebookClient.publish(facebookWallURL, FacebookType.class,BinaryAttachment.with("dreidel.jpg", url.openStream()), postParamsArray); 

但是,我看到時間軸只有文字上:我的消息。

用戶具有以下權限:

'manage_pages, publish_stream, create_event, photo_upload' 

可能是什麼問題呢?

回答

3

facebookWallURL - 看起來像你張貼到牆上。嘗試張貼的專輯,而不是:

facebookURL = facebookPageId + "/photos"; 
publishMessageResponse = facebookClient.publish(facebookURL, FacebookType.class, ba, postParamsArray); 

寫在這個例子:
(注意:「我/視頻」
http://restfb.com/

Publishing a Photo (see Graph API documentation) 

// Publishing an image to a photo album is easy 
// Just specify the image you'd like to upload and RestFB will handle it from there. 

FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class, 
    BinaryAttachment.with("cat.png", getClass().getResourceAsStream("/cat.png")), 
    Parameter.with("message", "Test cat")); 

out.println("Published photo ID: " + publishPhotoResponse.getId()); 

// Publishing a video works the same way as uploading a photo. 

facebookClient.publish("me/videos", FacebookType.class, 
    BinaryAttachment.with("cat.mov", getClass().getResourceAsStream("/cat.mov")), 
    Parameter.with("message", "Test cat")); 
+0

@urlr它不是爲我工作.. ...在線程「main」中顯示異常異常java.lang.IllegalArgumentException:二進制附件數據不能爲空。 –

+0

@sooraj這只是意味着你的流實際上是空的。這段代碼將getClass()。getResourceAsStream(「/ cat.png」)轉換爲單獨的屬性,並查看它可能爲空。解決你的文件加載和代碼將完美工作。 – urir

相關問題