Python Facebook Oembed

Apr 16, 2020
import requestsfrom urllib.parse import urlencodeurl = 'https://www.facebook.com/nixonsiow/posts/3093544747376885'# url = 'https://www.facebook.com/brian.john.crowley/videos/10158058811332822/'query_string = urlencode({'url': url}) # , 'omitscript': Trueoembed_url = f"https://www.facebook.com/plugins/post/oembed.json?{query_string}"# another endpoint for video, but plugins/post/oembed.json work for video link as well# oembed_url = f"https://www.facebook.com/plugins/video/oembed.json?{query_string}"r = requests.get(oembed_url)if r.status_code == 200:    result = r.json()    html = result['html'].strip()
{  "author_name": "Nixon Siow",  "author_url": "https://www.facebook.com/nixonsiow/",  "provider_url": "https://www.facebook.com",  "provider_name": "Facebook",  "success": true,  "height": null,  "html": "<div id=\"fb-root\"></div>\n<script async=\"1\" defer=\"1\" crossorigin=\"anonymous\" src=\"https://connect.facebook.net/ms_MY/sdk.js#xfbml=1&amp;version=v6.0\"></script><div class=\"fb-post\" data-href=\"https://www.facebook.com/nixonsiow/posts/3093544747376885\" data-width=\"552\"><blockquote cite=\"https://www.facebook.com/nixonsiow/posts/3093544747376885\" class=\"fb-xfbml-parse-ignore\"><p>A very very quick sketch for sharing during this difficult moment.\n#tqfrontliners #covid19\n\np/s: sorry for the bad drawing, and bad English</p>Posted by <a href=\"https://www.facebook.com/nixonsiow/\">Nixon Siow</a> on&nbsp;<a href=\"https://www.facebook.com/nixonsiow/posts/3093544747376885\">Sabtu, 21 Mac 2020</a></blockquote></div>",  "type": "rich",  "version": "1.0",  "url": "https://www.facebook.com/nixonsiow/posts/3093544747376885",  "width": 552}

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.