我正在构建一个脚本,使用ruby / pg / ActiveRecord / TweetStream(gem)将推文保存到postgres数据库。
这个脚本工作正常..
...
TweetStream::Client.new.track(SEARCH_TERMS) do |t|
puts "#{t.text}"
attributes = {
tweetid: t[:id],
text: t.text,
in_reply_to_user_id: t.in_reply_to_user_id,
in_reply_to_status_id: t.in_reply_to_status_id,
received_at: t.created_at,
user_statuses_count: t.user.statuses_count,
user_followers_count: t.user.followers_count,
user_profile_image_url: t.user.profile_image_url,
user_screen_name: t.user.screen_name,
user_timezone: t.user.time_zone,
user_location: t.user.location,
user_lang: t.lang,
user_id_str: t.user.id,
user_name: t.user.name,
user_url: t.user.url,
user_created_at: t.user.created_at,
user_geo_enabled: t.user.geo_enabled,
}
if StoreTweet.create(attributes)
puts "saved"
else
puts "error"
end
end
直到我添加
user_geo_enabled: t.user.geo_enabled,
coordinates: t.coordinates.coordinates,}
我也试过
t.coordinates
t.coordiantes[:coordinates]
t[:coordinates] #this allows me to save but is always blank if when geo_enabled is 'true'
Twitter开发中心(https://dev.twitter.com/docs/platform-objects/tweets)告诉我'坐标'是浮动的集合,如:
"coordinates":
{
"coordinates":
[
-75.14310264,
40.05701649
],
"type":"Point"
}
目前我使用'text'字段。我应该将哪种类型赋予字段以便将两个值存储在一起?