Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

youtube - 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?

question from:https://stackoverflow.com/questions/5227607/posting-an-embedded-video-link-using-the-facebook-graph-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...