gpt4 book ai didi

ruby-on-rails - 无法从 twitter gem 解析哈希

转载 作者:数据小太阳 更新时间:2023-10-29 08:20:47 26 4
gpt4 key购买 nike

我的 gem 正在运行:可以从中发送推文并获取信息。

我可以获取此散列并打印出它的 .text 部分,但我不知道如何获取 id_str 和 screen_name - 我确实需要解析的信息。

不确定我做错了什么。

  <% Twitter.mentions_timeline.each do |mention| %>
<%= mention.text %> <%# dies on some of em, like mention.id_str - not sure why %>
<br /><hr />
<% end %>

下面是 Twitter.mentions_timeline 哈希:

[#<Twitter::Tweet:0x007fd070de24a0 




@attrs={
:in_reply_to_status_id_str=>"265276218855809024",
:retweet_count=>0,
:contributors=>nil,
:truncated=>false,
:text=>"@doodleboots http://t.co/VJOR0MgQ",
:in_reply_to_user_id_str=>"119208666",
:geo=>nil,
:retweeted=>false,
:possibly_sensitive=>false,
:in_reply_to_screen_name=>"doodleboots",
:id_str=>"265276345704124416",
:entities=>{:hashtags=>[],
:urls=>[{:display_url=>"is.gd/S3uOyu",
:indices=>[13, 33],
:expanded_url=>"http://is.gd/S3uOyu",
:url=>"http://t.co/VJOR0MgQ"}],
:user_mentions=>[{:name=>"doodle",
:indices=>[0, 12],
:screen_name=>"doodleboots",
:id_str=>"119208666",
:id=>119208666}]},
:in_reply_to_user_id=>119208666,
:in_reply_to_status_id=>265276218855809024,
:created_at=>"Mon Nov 05 02:16:24 +0000 2012",
:place=>nil,
:user=>{:profile_image_url_https=>"https://si0.twimg.com/profile_images/2808322935/d5da93a06dbd45959cb4dba0797689a5_normal.jpeg",
:id=>926557182,
:profile_background_image_url=>"http://a0.twimg.com/images/themes/theme1/bg.png",
:entities=>{:description=>nil},
:screen_name=>"Roslyn1bdzn",
:profile_link_color=>"0084B4",
:default_profile_image=>false,
:created_at=>"Mon Nov 05 01:17:20 +0000 2012",
:contributors_enabled=>false,
:friends_count=>0,
:time_zone=>nil,
:favourites_count=>0,
:utc_offset=>nil,
:profile_use_background_image=>true,
:url=>nil, :geo_enabled=>false,
:lang=>"en",
:profile_image_url=>"http://a0.twimg.com/profile_images/2808322935/d5da93a06dbd45959cb4dba0797689a5_normal.jpeg",
:profile_text_color=>"333333",
:name=>"Roslyn Montalbo ",
:profile_background_image_url_https=>"https://si0.twimg.com/images/themes/theme1/bg.png",
:description=>"Amateur social media scholar. Friend of animals everywhere. Explorer. Unapologetic twitter advocate. Incurable travel geek. Writer",
:protected=>false,
:profile_sidebar_border_color=>"C0DEED",
:followers_count=>0,
:default_profile=>true,
:profile_background_tile=>false,
:location=>"Dublin",
:profile_sidebar_fill_color=>"DDEEF6",
:following=>false,
:statuses_count=>3,
:follow_request_sent=>false,
:listed_count=>0,
:id_str=>"926557182",
:profile_background_color=>"C0DEED",
:notifications=>false,
:verified=>false,
:is_translator=>false},
:coordinates=>nil,
:source=>"web",
:favorited=>false,
:id=>265276345704124416}>,



#<Twitter::Tweet:0x007fd070de2478

@attrs={:in_reply_to_status_id_str=>nil,
:retweet_count=>0,
:contributors=>nil,
:truncated=>false,
:text=>"test post @doodleboots",
:in_reply_to_user_id_str=>nil,
:geo=>nil,
:retweeted=>false,
:in_reply_to_screen_name=>nil,
:id_str=>"247909685582233600",
:entities=>{:hashtags=>[],
:urls=>[],
:user_mentions=>[{:name=>"doodle",
:indices=>[10, 22],
:screen_name=>"doodleboots",
:id_str=>"119208666",
:id=>119208666}]},
:in_reply_to_user_id=>nil,
:in_reply_to_status_id=>nil,
:created_at=>"Tue Sep 18 04:07:29 +0000 2012",
:place=>nil,
:user=>{:profile_image_url_https=>"https://si0.twimg.com/profile_images/728693845/doodleBootsIcon_normal.png",
:id=>119208666,
:profile_background_image_url=>"http://a0.twimg.com/images/themes/theme1/bg.png",
:entities=>{:description=>{
:urls=>[]},
:url=>{:urls=>[{
:display_url=>nil,
:indices=>[0, 22],
:expanded_url=>nil,
:url=>"http://doodleboots.com"}]}},
:screen_name=>"doodleboots",
:profile_link_color=>"0084B4",
:default_profile_image=>false,
:created_at=>"Wed Mar 03 00:09:50 +0000 2010",
:contributors_enabled=>false,
:friends_count=>16,
:time_zone=>nil,
:favourites_count=>0,
:utc_offset=>nil,
:profile_use_background_image=>true,
:url=>"http://doodleboots.com",
:geo_enabled=>false,
:lang=>"en",
:profile_image_url=>"http://a0.twimg.com/profile_images/728693845/doodleBootsIcon_normal.png",
:profile_text_color=>"333333",
:name=>"doodle",
:profile_background_image_url_https=>"https://si0.twimg.com/images/themes/theme1/bg.png",
:description=>"Take a pic of a drawing/doodle and tweet it @doodleboots! It will be re-tweeted and posted to the website for all to see.",
:protected=>false,
:profile_sidebar_border_color=>"C0DEED",
:followers_count=>14,
:default_profile=>true,
:profile_background_tile=>false,
:location=>"",
:profile_sidebar_fill_color=>"DDEEF6",
:following=>false,
:statuses_count=>16,
:follow_request_sent=>false,
:listed_count=>1,
:id_str=>"119208666",
:profile_background_color=>"C0DEED",
:notifications=>false,
:verified=>false,
:is_translator=>false},
:coordinates=>nil,
:source=>"web",
:favorited=>false,
:id=>247909685582233600}>,

最佳答案

Twitter::Tweet 类不公开 id_str 属性。这些是公开的属性(来自 https://github.com/sferik/twitter/blob/master/lib/twitter/tweet.rb 的源代码):

:favorited, :favoriters, :from_user_id, :from_user_name,
:in_reply_to_screen_name, :in_reply_to_attrs_id, :in_reply_to_status_id,
:in_reply_to_user_id, :iso_language_code, :profile_image_url,
:profile_image_url_https, :repliers, :retweeted, :retweeters, :source,
:text, :to_user, :to_user_id, :to_user_name, :truncated

如果您需要访问任何其他内容,请通过 attrs 哈希访问它:

@tweet.attrs[:id_str]

关于ruby-on-rails - 无法从 twitter gem 解析哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13248874/

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