Alon Adler
Alon Adler

Reputation: 4024

Post YouTube video into a Facebook Event Wall

I try to post a YouTube video directly into a Facebook Event wall, using the Graph API.

When posting to a FanPage wall I get a desired result (Post with preview picture and the video itself), But when posting to an event wall, I only get the message, without any video and preview picture.

Here's the code:

var eventObj =
{
    source:'http://www.youtube.com/v/'+youTubeID,
    picture:'http://img.youtube.com/vi/'+youTubeID+'/0.jpg',
    message: messageText,
    name: eventName,
    caption: newDateArray[0] + ' ' + newDateArray[1].substr(0, 5)
}; 

FB.api('/'+facebookEventID+'/feed', 'post', eventObj, function(response){

//response code...

}

After this code is executed, I get a new post in the Event Wall, with only the messageText being displayed. I've tried sending only the source, but then it returns an error object with message it cant create a post without a message, so I tried sending both source and message and got the same result: only the message was displayed.

UPDATE BASED ON ANSWER:

I've tried using your code and your permissions, and the results are the same:

I get only the text:

enter image description here

Maybe its because I'm posting as a FanPage ? Do you have any idea how to solve it ?

UPDATE #2 BASED ON ANSWER:

It seems that for some reason an event created from within Facebook has a newer version of the post UI then an event created from an application using the Graph API.

This is from the event created within Facebook: enter image description here

And this is from the event created with the Graph API: enter image description here

You can see the second is an older version, and I guess this difference is also causing the problem of uploading YouTube links to events created by the Graph API, As I succeed uploading a YouTube link from the API to an event created by me from within Facebook.

Upvotes: 1

Views: 6300

Answers (1)

Donn Lee
Donn Lee

Reputation: 3149

Really? I was able to post a YouTube link to an event using my test app:

function post() {
  var eid = 508688182476978;  // Event id.                                                                 
  FB.api(
    '/' + eid + '/feed',
    'post',
    {
      message: 'Testing SDK',
      source: 'http://www.youtube.com/v/kohozJp9dNs',
      picture: 'http://img.youtube.com/vi/kohozJp9dNs/0.jpg',
      caption: 'beach video (caption)'
    },
    function(response) {
      if (!response || response.error) {
        console.log(response);
        alert('Error occured');
      } else {
        alert('Post was successful! Action ID: ' + response.id);
      }
    }
  );
}

...and it shows the video's picture preview and caption:

youtube link on an event

...with these perms

publish_actions,read_stream,user_events,publish_stream

I did not need the name param like in your example.

Events created via the API

If you are creating Events using the API (not creating them using a web browser), try enabling the 'Events Timezone' migration:

App Dashboard > Advanced > Migrations > Events Timezone > Enable

See also announcement of that migration: https://developers.facebook.com/blog/post/2012/08/01/platform-migration--events-timezone-support/

Once the Events Timezone migration is enabled for your app, create a new event using the api, and then try posting the YouTube video story as written above in function post().

Upvotes: 2

Related Questions