Twitter API を操作して、Web サイトに user_timeline を表示しようとしています。
Twitter 統合については railscasts.com のビデオをフォローしました: http://railscasts.com/episodes/359-twitter-integration
私は API を問題なく操作しており、アプリケーションに情報を取り込み、表示して開発を行っています。
私のコードは次のとおりです。
モデル-timeline.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でも別のエラーが発生しました。
ありがとう。