Skip to main content
 首页 » 编程设计

python之我怎样才能获得用于 reddit 评论的 oembed json

2025年04月02日14zhujiabin

我正在尝试使用 python-oembed 库从 reddit(https://github.com/reddit/reddit/wiki/oEmbed)获取 oembed 评论:

import oembed 
 
consumer = oembed.OEmbedConsumer() 
endpoint = oembed.OEmbedEndpoint('https://www.reddit.com/oembed',['https://www.reddit.com/r/*']) 
 
consumer.addEndpoint(endpoint) 
 
response = consumer.embed('https://www.reddit.com/r/Showerthoughts/comments/2safxv/we_should_start_keeping_giraffes_a_secret_from/cno7zic') 

并得到 oembed.OEmbedError: Missing required fields on OEmbed rich response. 错误。

如何检索这些数据?

请您参考如下方法:

reddit返回的oembed无效。

来自 http://oembed.com/ , §2.3.4.4, width 和 height 是 rich 类型所必需的。

但是,来自the reddit sample ,我们看到 reddit 不提供 width 或 height 值。

您可能需要获取 reddit 来修复他们损坏的 oembed 实现,或者您可能想要使用更宽容的库。