【发布时间】:2012-07-02 10:37:41
【问题描述】:
我正在尝试与 Twitter API 交互以在我的网站上显示 user_timeline。
我关注了 railscasts.com 的 Twitter 集成视频:http://railscasts.com/episodes/359-twitter-integration
我可以很好地与 API 交互,将信息提取到我的应用程序中,它正在显示并在开发中工作。
我的代码如下:
模型 - 时间线.rb
class Timeline < ActiveRecord::Base
attr_accessible :content, :screen_name, :tweet_id
def self.pull_tweets
Twitter.user_timeline("{username_goes_here}", since_id: maximum(:tweet_id)).each do |tweet|
unless exists?(tweet_id: tweet.id)
create!(
tweet_id: tweet.id,
content: tweet.text,
screen_name: tweet.user.screen_name,
)
end
end
end
end
这里是迁移:
class CreateTimelines < ActiveRecord::Migration
def change
create_table :timelines do |t|
t.string :tweet_id
t.string :screen_name
t.text :content
t.timestamps
end
结束 结束
并显示推文:
<div id="timeline">
<% Timeline.order("tweet_id desc").limit(3).each do |timeline| %>
<h3><%= timeline.content %></h3>
<p class="pull-right">
~ @<%= timeline.screen_name %>
</p>
<% end %>
</div>
这个想法是将推文存储在数据库中,这样即使 Twitter 关闭,也不会影响查看最新推文的用户。
无论如何,当我在控制台中运行命令Timeline.pull_tweets 时,它工作正常。
当我推送到 heroku、迁移数据库并尝试运行相同的命令时。
然后我得到这个错误:
PGError: ERROR: operator does not exist: character varying = bigint
LINE 1: ...ne FROM "timelines" WHERE "timelines"."tweet_id" = 21919081...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
有什么帮助吗?
我还尝试运行迁移,以便 :tweet_id 是一个整数,但我在 heroku 上也遇到了另一个错误。
谢谢。
【问题讨论】:
标签: ruby-on-rails sqlite postgresql heroku twitter