Claes Gustavsson
Claes Gustavsson

Reputation: 5689

Embed video on facebook feed with javascript api?

Im trying to embed a video on my facebook PAGE feed-wall with the below code. It uploads to facebook, but the thumbnail image is not showed and the video is not embeded. It displays a link, that opens the video in a new seperate window.

FB.api('/' + page_id, {fields: 'access_token'}, function(resp2) {
        if(resp2.access_token) {
            FB.api('/' + page_id + '/feed', 'post',{

                message: headline +' \n'+ texten, 
                access_token: resp2.access_token,
                picture: imgURL,
                embed_html:"<object width=\"480\" height=\"360\" ><param name=\"allowfullscreen\" value=\"true\" /><param name=\"movie\" value=\"http://www.facebook.com/v/<%=facebookPageId%>\" /><embed src=\"http://www.facebook.com/v/<%=facebookPageId%>\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"480\" height=\"360\"></embed></object>" ,
                width: 480, 
                height: 360,
                source : videoURL,
                name   : headline,//rubriken brevid thumbnail bilden
                link   : videoURL//länken dit rubriken pekar, måste ha ett värde annars går länken till bilden på appmanagern!!!
                //description : '<'%=facebookDescription%>'
                }

I dont know what Im missing, any input appreciated, thanks!

I fixed it! See below.

Upvotes: 2

Views: 2761

Answers (1)

Claes Gustavsson
Claes Gustavsson

Reputation: 5689

I tought that I would share how to upload and embed a video on a Facebook PAGE feed with the Facebook graph javascript api!

  1. You have to create a facebook app - you need the app id when you log in the user.
  2. You also have to ask for the user permission when he logs in - I have publish_stream, read_stream, user_videos etc.
  3. Then when the user that is going to post to facebook have logged in to facebook with the right permissions, then ....
  4. I downloaded the latest JW Player files and uploaded the jwplayer.js and player.swf files to my server in the same folder as this code.
  5. And I use the below code:

    function postToPage2() {

    var imgURL = 'http://www.mypage.com/images/image.jpg';
    var videoURL = 'http://www.mypage.com/video/video.mp4';
    var swfURL ='http://www.mypage.com/video/player.swf?file='+videoURL+'&autostart=true&controlbar=false';
    var page_id = 'my facebook page id';
    FB.api('/' + page_id, {fields: 'access_token'}, function(resp2) {
        if(resp2.access_token) {
            FB.api('/' + page_id + '/feed', 'post',{
    
                message: headline +' \n'+ texten, 
                access_token: resp2.access_token,
                picture: imgURL,
                width: 400, 
                height: 300,
                source : swfURL,
                name   : 'headline',
                link   : 'www.manmade.se',
                description : 'some text'
                }
    

This works the same if you upload to a ordinary facebook users aswell.

I hope you like it!

Upvotes: 3

Related Questions