jprim
jprim

Reputation: 1353

How do I enable inline video play when I send a link to facebook for YouTube videos via my app?

Facebook.prototype.post = function(options) {
var data =  { 
    access_token: this.data.token,
    // message: options.message,
    link: options.link,

};

if (options.type == 'image') data.picture = options.image;

var url = 'https://graph.facebook.com/me/feed';

if (options.friend !== undefined)
    url = 'https://graph.facebook.com/' + escape(options.friend) + '/feed';

$.ajax({
    type: 'post',
    dataType: 'json',
    url: url,
    data: data,
    success: options.success,
    error: options.error
});

};

See attached

Upvotes: 4

Views: 4261

Answers (1)

Kranu
Kranu

Reputation: 2567

How to view video:

Update: If you want to be able to embed a video based on the link you get from the facebook api, you could do something like:

<object width="640" height="385">
<param name="movie" value="http://www.youtube.com/v/vX07j9SDFcc?autoplay=1"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/vX07j9SDFcc?autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed>
</object>

Just replace the youtube link.

If you want it to autoplay, REMEMBER TO INCLUDE THE ?autoplay=1.

How to share video:

Here are two ways to do this:

METHOD 1: Open a Popup with the URL format:

http://www.facebook.com/sharer.php?u=[Youtube Link]

Sample code to implement this would be:

...onclick=function() {
  window.open('http://www.facebook.com/sharer.php?u=[Youtube Link]');
}

The popup that will open will look like: popup

METHOD 2: Use Javascript API:

This can look more professional because you can display your message as an overlay iframe.

 var share = {
   method: 'stream.share',
   u: '[Youtube Link]'
 };

 FB.ui(share, function(response) { console.log(response); });

Here's the documentation I based my code from:

http://developers.facebook.com/docs/reference/javascript/FB.ui

RESULT:

Either way, after the user clicks share, it should appear in the news feed:Example Screenshot

Upvotes: 4

Related Questions