2012-10-17 24 views
0

有沒有辦法從狀態標識(234552300176293888)中提取用戶標識(331063009)?如果有答案,Ruby更可取。Twitter/Ruby - 狀態ID中的用戶ID?

響應從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"}} 
+0

請更好地描述你的問題。什麼狀態ID的用戶ID?絕對沒有關於它們是什麼的信息。 –

+0

你有什麼嘗試? [Twitter API]是否存在問題(https://dev.twitter.com/docs/api/1.1/get/statuses/show/%3Aid)? – willglynn

+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。

+0

是否有一個非限制率的方式來做到這一點? –

+0

不可以。每個Twitter交互都會計入您的費率限制。這通常不是問題,因爲所有給你一個狀態ID的東西也已經給你了用戶ID。你不應該*有*做追溯。 – willglynn