Posting an embedded video link using the Facebook Graph API

风格不统一 提交于 2019-11-27 10:32:00
Anomie

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.

dandan

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
                }

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

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.

giorgos

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.

Devaroop

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

message = your message + link

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!