41

When manually attaching a video link (from YouTube, Vimeo, etc) to a post using the Facebook web interface, Facebook automatically recognizes the link as a video, and allows the resulting status message to play the video inline. The video is displayed as an embedded player in the Wall or News feed.


Here's an example of what an embedded video looks like after posting manually.

Embedded Video


When posting a link using the Graph API, the video is not embedded.

curl -F 'access_token=...' \
     -F 'message=Link to YouTube' \
     -F 'link=http://www.youtube.com/watch?v=3aICB2mUu2k' \
     https://graph.facebook.com/me/feed

Not-Embedded Video


I suspect the answer is related to the source argument, but I'm not sure what the URL should be there. Specifying the same URL just leads to a post with no thumbnail image whatsoever.

source: A URL to a Flash movie or video file to be embedded within the post. read_stream.

How can the same embedded behavior be accomplished by using the Graph API alone?

Ryan McGeary
  • 235,892
  • 13
  • 95
  • 104
  • the images are not visible anymore, possibly they should be uploaded on SE. – Herbert May 11 '15 at 14:36
  • @Herbert Sorry, these images were hosted with Skitch before Stack Overflow hosted images themselves. I no longer have a copy of those screenshots. And Skitch (aka Evernote) killed their old URL patterns: https://discussion.evernote.com/topic/80874-old-skitch-image-urls-all-broken/ – Ryan McGeary May 11 '15 at 21:55

7 Answers7

49

It appears that you have to extract the URLs of the actual swf in the page and the thumbnail image yourself. For example, this seems to work:

curl -F 'access_token=...' \
     -F 'message=Link to YouTube' \
     -F 'link=http://www.youtube.com/watch?v=3aICB2mUu2k' \
     -F 'source=http://www.youtube.com/v/3aICB2mUu2k' \
     -F 'picture=http://img.youtube.com/vi/3aICB2mUu2k/0.jpg' \
     https://graph.facebook.com/me/feed

It appears that you can generate a valid source and picture from the page URL. The URL looks like http://www.youtube.com/watch?v=<code>; take the code (3aICB2mUu2k here) and insert it into the URLs http://www.youtube.com/e/<code> for the source and and http://img.youtube.com/vi/<code>/0.jpg for the picture.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Anomie
  • 92,546
  • 13
  • 126
  • 145
  • 2
    +1, but this no longer works. the source argument is not only ignored, but also makes the picture argument ignored. Could you whether my observations are correct? – Bozho Apr 03 '11 at 20:04
  • the problem appeared to be..that I used `http://youtube.com` for the embed link rather than `http://www.youtube.com`. Now it works. But facebook could've followed that redirect.. :) – Bozho Apr 04 '11 at 16:35
  • This doesn't seem to work for vimeo, anyone have any luck there? I used to be able to use similar code on the old rest based API for vimeo and YouTube, but no so much with graph. – covati Oct 09 '11 at 18:14
  • 5
    what about for a non-YouTube based video? –  Nov 10 '11 at 07:13
  • To extract the right links for source, picture, and url, parse the appropriate open graph meta params on the page itself! og:image, og:video, og:url. For Ruby (with Nokogiri) it would be `doc.xpath('//meta[@property="og:video"]/@content').map(&:value).first` – PrasannaK Jul 16 '12 at 15:25
  • @PrasannaK, what do you mean the "page itself"? There is no "page" this is a curl call! Are you suggesting that one of the params should point to a page that has these embedded tags? If so, which one? – Yevgeny Simkin Jan 29 '13 at 03:45
  • I agree with Bozho, the source argument does appear to do nothing and interfere with the picture argument (my assumption is that when they see the source argument they just ignore the picture argument). I don't have a www in my URL so... this simply fails. – Yevgeny Simkin Jan 29 '13 at 03:50
  • I realize this answer is over a year old, but it is no longer correct. The specific code provided as sample produces an authorization error (which appears to be incorrect since my app has the rights to post to the wall and does so successfully with images). – Yevgeny Simkin Jan 29 '13 at 05:44
  • @Dr.Dredel Page = the youtube page being linked. – PrasannaK Feb 10 '13 at 15:24
  • I would just like to add one more point, when you click picture it wont autoplay video and rather shows one more link with a picture to click to play. To avoid this just add one more parameter, autoplay=1. So your source URL must be something like this - http://www.youtube.com/e/VIDEO_ID?autoplay=1. Hope that helps. – Vijayendra Mar 15 '11 at 19:03
6

Here's how to post a video manually for YOUTUBE and VIMEO (hard to find online). Specifically if you want to have the LINK value pointing to a user's website/blog post where it originates.

                //search for youtube.com and vimeo.com in the 'link' value
                if (preg_match("/youtube.com/", $model->link) || preg_match("/youtu.be/", $model->link)){
                    if (preg_match('%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $model->link, $match))
                    {
                        $video_code = $match[1];
                    }
                   $source = 'http://www.youtube.com/e/'.$video_code; 
               $picture = 'http://img.youtube.com/vi/'.$video_code.'/0.jpg';
                }
                else if (preg_match("/vimeo.com/", $model->link))
                {
                    if (preg_match('/vimeo\.com\/(clip\:)?(\d+).*$/', $model->link, $match))
                    {
                        $video_code = $match[2];
                     }
                    /* Get Vimeo thumbnail */
                    $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$video_code.php"));
                    $picture = $hash[0]['thumbnail_medium'];  
                    $source = 'https://secure.vimeo.com/moogaloop.swf?clip_id='.$video_code.'&autoplay=1';
                }

                $args = array(
                'message'   => //user's comment
                'name' => //Title of post
                'link'      => 'http://...'//link to video on user's website

                'source' => $source,
                'picture' => $picture,
                );

                if ($this->_facebook->api("/".$this->facebookUserID."/feed", "post", $args)){
                //posted to facebook
                }
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
dandan
  • 1,016
  • 8
  • 16
  • If I put the url of the page where the video is embedded in the 'link' property, I get an image preview and not a video preview on Facebook. Can you really have a different value for 'source' and 'link' ? – Sulli Oct 05 '16 at 13:20
4

Sharing as a link with /links instead of /feed seems to work better. YouTube, Vimeo, and Facebook videos are embedded as if posting manually.

curl -F 'access_token=...' \
     -F 'message=Link to YouTube' \
     -F 'link=http://www.youtube.com/watch?v=3aICB2mUu2k' \
     https://graph.facebook.com/me/links
mindriot
  • 14,149
  • 4
  • 29
  • 40
1

It will not work for posting in GROUPS on /feeds or /links. See here. Please upvote the issue in order to be fixed sometime soon.

/links is a duplicate of the /feeds which only shows posts of type link posted by the user themselves.

Matt
  • 74,352
  • 26
  • 153
  • 180
giorgos
  • 158
  • 2
  • 8
  • giorgos, I appreciate this answer was posted a while ago, but please avoid using URL shorteners in future. Your post has a limit of 65535 characters, so there should be no reason to use a URL shortener. – Matt Jul 31 '15 at 08:29
1

Don't use /feed, use /links (https://graph.facebook.com/me/links/ ) and simply POST "message" and "link" parameters using the YouTube /watch?v=ZL7nV7WwJKg URL format. /feed never worked for me, it just posted a static graphic and link but I wanted it to actually play embedded on Facebook as it does when you share the Video from YouTube to Facebook. Works like a charm.

0

Sharing using the API any .swf file or video wont show a thumbnail on facebook unless its youtube . And that is by design as per facebook. Check this link

https://developers.facebook.com/bugs/589975484398226?browse=external_tasks_search_results_526fc388b99e18881434478

0

Instead try posting the link as the message attribute, it works for me that way.

message = your message + link
Kyle Trauberman
  • 25,414
  • 13
  • 85
  • 121
Devaroop
  • 7,900
  • 2
  • 37
  • 34
  • If the post if of the form (text + link + text) then better include the whole thing in the message attribute. It works even without specifying link = .... – Devaroop Sep 06 '11 at 09:44