Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting an embedded video link using the Facebook Graph API

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?

like image 908
Ryan McGeary Avatar asked Mar 08 '11 02:03

Ryan McGeary


People also ask

Can you post an embedded link on Facebook?

Embed a link into your status update by pasting the link into the provided box. Facebook will automatically grab a snippet of information from the linked page, as well as an image, and format it for you. You can then delete the link from the status update box and type a description if you wish.

Does Facebook allow iframe?

Simply set Facebook Feed and embed it on your iFrame website Create a unique iFrame Facebook page widget in our demo and get installation code to put in on your site. Embed the code into the page of your site or template, where you plan the widget. Done! Facebook Feed widget is installed on your iframe website.


5 Answers

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.

like image 112
Anomie Avatar answered Sep 28 '22 20:09

Anomie


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
                }
like image 38
dandan Avatar answered Sep 29 '22 20:09

dandan


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
like image 37
mindriot Avatar answered Sep 29 '22 20:09

mindriot


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.

like image 29
Jacob Robinson Avatar answered Sep 30 '22 20:09

Jacob Robinson


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.

like image 43
giorgos Avatar answered Oct 01 '22 20:10

giorgos