2012-12-04 2 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); 

: 그것은 나를 위해 작동하지 않습니다 @urlr

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

("나/비디오"주의) .. ... 예외를 표시하는 스레드 "main"예외 java.lang.IllegalArgumentException : 이진 첨부 데이터를 null 일 수 없습니다. –

+0

@sooraj 이것은 스트림이 실제로 null임을 의미합니다. 이 코드는 getClass(). getResourceAsStream ("/ cat.png")을 별도의 속성으로 만들고 null 일 가능성이 높습니다. 파일 로딩을 해결하면 코드가 완벽하게 작동합니다. – urir

관련 문제