Question

I am developing a Facebook Application an i wanna send a video file from myServer to Facebbok User`s Timeline. This is the page with the explanation http://developers.facebook.com/blog/post/515/#video_upload but its a PHP code.

My app is on Grails, and im looking in HTTBuilder class but can't find a way to do this. Do someone know how to do it?

If isnt possible to do this with HTTPBuilder, in my app, i am using Spring Social Facebook Plugin on Grais I found the interface MediaOperations but i dont know how to use this interface and use the method postVideo to upload a Video.

Thanks!

Was it helpful?

Solution

Will try to help a bit. You may use MediaOperations interface for this operation. Spring Social Facebook Plugin configures a service called Facebook for you. You can use it via dependency injection.

Here is a simple code example:

import org.springframework.social.facebook.api.Facebook

class FacebookService {
    Facebook facebook

    def uploadVideo(String videoFileName, String title, String description) {
         try {
             def videoResource = new FileSystemResource(videoFileName)
             facebook.mediaOperations().postVideo(videoResource, title, description) 
             return true
         } 
         catch (Exception e) {
             log.error("Error to upload video to facebook", e)
              return false
         }
    }
}

The video is loaded from the file in the FS by specified file path/name from videoFileName variable. This means, user need to upload the video first, and code should save it to some file in FS first, then upload. Usually this is the best case, as video files are large. Maybe there is a sense to upload the video to facebook in separate thread and don't give the user to wait.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top