java - Posting image to facebook page -
i want post images facebook page. below code tried restfb manual page. it's showing kind of error not getting understood. in publish("me/photos") should pass username instead of writing me?. image bird.jpg exists in project folder. can me? kind of appreciated
facebookclient facebookclient = null; facebooktype publishphotoresponse = facebookclient.publish("me/photos", facebooktype.class, binaryattachment.with("bird.jpg", facebookupload.class.getresourceasstream("/bird.jpg")), parameter.with("message", "test cat")); system.out.println("published photo id: " + publishphotoresponse.getid());
this error encountered
exception in thread "main" java.lang.illegalargumentexception: binary attachment data cannot null. @ com.restfb.binaryattachment.<init>(binaryattachment.java:68) @ com.restfb.binaryattachment.with(binaryattachment.java:113) @ pkg.am.ncrb.shot.facebookupload.main(facebookupload.java:31)
also tried below code
but none of working
inputstream = new fileinputstream(new file("bird.jpg")); facebooktype publishvideoresponse =facebookclient.publish("me/photos",facebooktype.class, binaryattachment.with("bird.jpg", is), parameter.with("message", "my photo post"));
and it's getting exception
exception in thread "main" java.lang.nullpointerexception @ pkg.am.ncrb.shot.facebookupload.main(facebookupload.java:35)
i need sample piece of code push image facebook. don't know went wrong.
in java, can't use object set
null
. you'llnullpointerexception
.the object
null
facebookclient
. should initialize it:facebookclient facebookclient = new defaultfacebookclient();
where putting photo? if it's embedded in jar file, use
facebookupload.class.getresourceasstream("/bird.jpg")
. if it's in current directory (probably), usenew fileinputstream(new file("bird.jpg"))
.
Comments
Post a Comment