使用 Facebook Graph API 发布嵌入视频链接

发布于 2024-10-20 18:55:35 字数 895 浏览 2 评论 0原文

当使用 Facebook Web 界面手动将视频链接(来自 YouTube、Vimeo 等)附加到帖子时,Facebook 会自动将该链接识别为视频,并允许生成的状态消息内嵌播放视频。视频在墙或新闻源中显示为嵌入式播放器。


以下是手动发布后嵌入式视频的外观示例。

嵌入视频


使用 Graph API 发布链接时,不会嵌入视频。

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


我怀疑答案与 source 参数有关,但我不确定 URL 应该是什么。指定相同的 URL 只会导致发布的帖子没有任何缩略图。

来源:Flash 影片或视频文件的 URL 嵌入帖子中。 读流。

如何单独使用 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

另类 2024-10-27 18:55:35

看来您必须自己提取页面中实际 swf 和缩略图的 URL。例如,这似乎可行:

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

您似乎可以从页面 URL 生成有效的源和图片。该网址类似于 http://www.youtube.com/watch?v=;获取代码(此处为 3aICB2mUu2k)并将其插入源 URL http://www.youtube.com/e/http://img。 youtube.com/vi//0.jpg 的图片。

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.

歌枕肩 2024-10-27 18:55:35

以下是如何手动发布 YouTube 和 VIMEO 视频(网上很难找到)。特别是如果您希望 LINK 值指向其来源的用户网站/博客文章。

                //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
                }

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
                }
青萝楚歌 2024-10-27 18:55:35

使用 /links 而不是 /feed 作为链接共享似乎效果更好。 YouTube、Vimeo 和 Facebook 视频就像手动发布一样嵌入。

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

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
没有你我更好 2024-10-27 18:55:35

不要使用 /feed,使用 /links (https://graph.facebook.com/me/links/ ),并使用 YouTube /watch?v=ZL7nV7WwJKg URL 格式简单地发布“消息”和“链接”参数。 /feed 对我来说从来没有用过,它只是发布了一个静态图形和链接,但我希望它能够实际嵌入在 Facebook 上播放,就像您将视频从 YouTube 分享到 Facebook 时一样。就像魅力一样。

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.

安静被遗忘 2024-10-27 18:55:35

它不适用于在 /feeds 或 /links 上的群组中发布。
请参阅此处。请对问题进行投票,以便尽快修复。

/links 是 /feeds 的重复项,
仅显示用户自己发布的链接类型的帖子。

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.

策马西风 2024-10-27 18:55:35

相反,请尝试将链接发布为消息属性,这对我有用。

message = your message + link

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

message = your message + link
生生不灭 2024-10-27 18:55:35

使用 API 共享任何 .swf 文件或视频都不会在 Facebook 上显示缩略图,除非是 YouTube 。这是 Facebook 设计的。
检查此链接

https://developers.facebook.com/bugs/589975484398226?browse=external_tasks_search_result s_526fc388b99e18881434478< /a>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文