gpt4 book ai didi

ruby-on-rails - Oembed 推文 - 推特 gem

转载 作者:行者123 更新时间:2023-12-04 03:41:57 25 4
gpt4 key购买 nike

这可能是一个非常简单的问题,但我不知道如何呈现嵌入的推文。

为简单起见,这是我的 Controller :

class TweetsController < ApplicationController

def index

@tweet = twitter_client.oembed('527501479142109184')

end

end

在 View 中,如果我只是执行以下操作,它只会显示对象:
<%= @tweet %>

#<Twitter::OEmbed:0x007fb878abc5d8>
经检查,这给出:
#<Twitter::OEmbed:0x007fb875cacd28 @attrs={:cache_age=>"3153600000", :url=>"https://twitter.com/HuayuanSong/statuses/527501479142109184", :height=>nil, :provider_url=>"https://twitter.com", :provider_name=>"Twitter", :author_name=>"Huayuan Song", :version=>"1.0", :author_url=>"https://twitter.com/HuayuanSong", :type=>"rich", :html=>"<blockquote class=\"twitter-tweet\"><p>Jeg kunne lide en video på <a href=\"https://twitter.com/YouTube\">@YouTube</a> <a href=\"http://t.co/hhhTvyJA6y\">http://t.co/hhhTvyJA6y</a> Obama: U.S. leading the way against Ebola spread</p>&mdash; Huayuan Song (@HuayuanSong) <a href=\"https://twitter.com/HuayuanSong/status/527501479142109184\">October 29, 2014</a></blockquote>\n<script async src=\"//platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>", :width=>550}>

显然,这非常简单,我只是将其用作概念证明类型的东西。有人可以解释我如何从拥有对象到能够显示实际嵌入的推文吗?

谢谢

最佳答案

只需调用@tweet只会引用对象。为了显示您想要调用的推文:

<%= raw(@tweet.html) %>

另外,来自 Twitter 的 documentation :

The returned HTML snippet will be automatically recognized as an Embedded Tweet when Twitter’s widget JavaScript is included on the page.



Javascript 片段如下所示:
<script>
window.twttr = (function (d, s, id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src= "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function (f) { t._e.push(f) } });
}(document, "script", "twitter-wjs"));
</script>

关于ruby-on-rails - Oembed 推文 - 推特 gem ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26637030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com