Twitter / Ruby - 状态ID中的用户ID?

时间:2012-10-17 19:21:47

标签: ruby twitter

有没有办法从状态ID(234552300176293888)中提取用户ID(331063009)?如果有答案,Ruby答案更可取。

回复来自Twitter的REST API(https://dev.twitter.com/docs/api/1.1/)

我希望将推文和用户信息分成两个独立的数据库,而不是一个存储状态所属的文档。我更喜欢搜索查询(小数据集)。

示例回复:

{"_id"=>331063009,
 "attrs"=>
  {"default_profile_image"=>true,
   "id"=>331063009,
   "contributors_enabled"=>false,
   "geo_enabled"=>false,
   "favourites_count"=>0,
   "verified"=>false,
   "followers_count"=>6,
   "profile_background_image_url"=>
    "http://a0.twimg.com/images/themes/theme1/bg.png",
   "profile_link_color"=>"0084B4",
   "show_all_inline_media"=>false,
   "profile_background_image_url_https"=>
    "https://si0.twimg.com/images/themes/theme1/bg.png",
   "notifications"=>false,
   "utc_offset"=>nil,
   "time_zone"=>nil,
   "follow_request_sent"=>false,
   "name"=>"ZORO",
   "profile_use_background_image"=>true,
   "protected"=>false,
   "profile_text_color"=>"333333",
   "default_profile"=>true,
   "url"=>nil,
   "created_at"=>"Thu Jul 07 15:58:34 +0000 2011",
   "lang"=>"en",
   "profile_sidebar_border_color"=>"C0DEED",
   "statuses_count"=>1,
   "profile_image_url_https"=>
    "https://si0.twimg.com/sticky/default_profile_images/default_profile_4_normal.png",
   "description"=>"",
   "listed_count"=>0,
   "profile_image_url"=>
    "http://a0.twimg.com/sticky/default_profile_images/default_profile_4_normal.png",
   "id_str"=>"331063009",
   "friends_count"=>24,
   "profile_background_tile"=>false,
   "profile_sidebar_fill_color"=>"DDEEF6",
   "location"=>"",
   "is_translator"=>false,
   "status"=>
    {"in_reply_to_status_id_str"=>nil,
     "favorited"=>false,
     "in_reply_to_user_id_str"=>nil,
     "in_reply_to_user_id"=>nil,
     "coordinates"=>nil,
     "retweeted"=>false,
     "retweet_count"=>0,
     "in_reply_to_status_id"=>nil,
     "source"=>
      "<a href=\"http://twitter.com/tweetbutton\" rel=\"nofollow\">Tweet Button</a>",
     "contributors"=>nil,
     "in_reply_to_screen_name"=>nil,
     "truncated"=>false,
     "id"=>234552300176293888,
     "possibly_sensitive"=>false,
     "id_str"=>"234552300176293888",
     "place"=>nil,
     "geo"=>nil,
     "text"=>
      "The Cool Gadgets - Quest for The Coolest Gadgets http://t.co/FGhpj4Gu via @thecoolgadgets",
     "created_at"=>"Sun Aug 12 07:30:00 +0000 2012"},
   "screen_name"=>"ZORO1959",
   "following"=>false,
   "profile_background_color"=>"C0DEED"}}

1 个答案:

答案 0 :(得分:1)

Twitter API直接公开您想要的数据。我使用Twitter API console来请求http://api.twitter.com/1/statuses/show/234552300176293888.json,它让我回来了:

{
  "id": 234552300176293900,
  "id_str": "234552300176293888",
  // ...
  "user":  {
    "id": 331063009,
    "id_str": "331063009",
    "name": "ZORO",
    "screen_name": "ZORO1959",
    // ...
  },
}

很高兴返回给定状态ID的用户ID。