我修改了创建一个 rake 任务的方法,该任务可以获取给定页面的签到量,并抛出 facebook-graph。我使用考拉宝石和导轨。
我通过创建一个 rake 任务来做到这一点:
task :get_likes => :environment do
require 'koala'
# Grab the first user in the database
user = User.first
# Loop throw every school & and call count_checkins
School.columns.each do |column|
user.facebook.count_checkins(column.name, user)
end
end
# Count like for every school else return 0
def count_checkins(name, u)
a = u.facebook.fql_query('SELECT checkins FROM page WHERE name = "' + name + '"')
if a[0].nil?
return 0
else
return b = a[0]["checkins"]
end
end
# Initialize an connection to the facebook graph
def facebook
@facebook ||= Koala::Facebook::API.new(oauth_token)
end
但我得到一个错误:
private method `count_checkins' called for #<Koala::Facebook::API:0x007fae5bd348f0>
编写 rake 任务的任何想法或更好的方法都会很棒!
在此处检查完整错误:https ://gist.github.com/shuma/4949213