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 #12

Closed confile closed 11 years ago

confile commented 11 years ago

I tried to publish an image to a user's facebook wall using:

def publishPhotoResponse = facebookClient.publishFile("me/photos", [message: "Test cat"], urlToImg)

urlToImg is the url to the jpg image file (e.g., http://www.mydomain.com/3324324 )

It always gives me a "File not found" error. What should I do?

benorama commented 11 years ago

The publishFile method you are calling is taking a local filePath:

def publish(String connection, Map parameters = [:], String filePath = '') {
   ...

If you want to publish a remote file, you can use another method signature which takes a fileInputStream:

def publish(String connection, Map parameters = [:], String fileName, FileInputStream fileInputStream) {
   ...
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)