agorapulse / grails-facebook-sdk

Facebook SDK Grails Plugin
http://agorapulse.github.com/grails-facebook-sdk/guide
30 stars 13 forks source link

File Not Found Exception while posting image to facebook wall #13

Closed confile closed 11 years ago

confile commented 11 years ago

This is what I did and it is not working. Do you have a working sample for me?

def userAccessToken = facebookContext.user.token
def facebookClient = new FacebookGraphClient(userAccessToken)
def someUrl = "http://www.google.com/images/logo.gif";
def file = File.createTempFile("facebookUpload",".temp").withOutputStream { out ->
    out << new URL(someUrl).openStream()
}
def publishPhotoResponse = facebookClient.publish("me/photos", [message: "Test cat"], file)

can you provide me some sample code which is working?

benorama commented 11 years ago

Hi Michael,

I've just release on new version of the plugin (0.4.4) where publish method takes InputStream argument type (instead of FileInputStream). So it should be much more easier now.

I've updated the docs:

// 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.
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test cat"], "/Users/ben/Downloads/cat.png")
println "Published photo ID: " + publishPhotoResponse.id
// Publish a submitted file
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test upload"], multipartFile.originalFilename, multipartFile.inputStream)
// Publish an existing remote file by URL
def someUrl = "http://www.google.com/images/logo.gif"
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test logo"], "logo.gif", new URL(someUrl).openStream())
println "Published photo ID: " + publishPhotoResponse.id
// Publishing a video works the same way.
facebookClient.publish("me/videos", [message, "Test cat"], "/Users/ben/Downloads/cat.mov")

Let me know if it is working as expected on your side.

Thanks!