0

ステータス ID (234552300176293888) からユーザー ID (331063009) を抽出する方法はありますか? 答えがあればRubyの答えが望ましいです。

レスポンスは Twitter の REST API (https://dev.twitter.com/docs/api/1.1/) からのものです。

ツイートとユーザー情報を 2 つの別々のデータベースに保存したいのですが、ステータスが誰に属しているかを保存するドキュメントも必要ありません。私はむしろ検索クエリ(小さなデータセット)を持っています。

応答例:

{"_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"}}
4

1 に答える 1

1

Twitter API は、必要なデータを直接公開します。Twitter API コンソールを使用してをリクエスト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 が喜んで返されます。

于 2012-10-17T19:44:50.623 に答える