install gem
[code language=”ruby”]
gem ‘koala’
[/code]
create rake tasks :
[code language=”ruby”]
namespace :social do
desc "Facebook Cloning"
task facebook: :environment do
fb_token = ‘token’
client = Koala::Facebook::API.new(fb_token)
begin
counts = 10 # change count to modify number of tweets fetched
@posts = client.get_connection(‘errakeshpd’,
‘posts’,{fields: [‘message’, ‘id’, ‘from’, ‘type’,’picture’, ‘link’, ‘created_time’, ‘updated_time’]}
)
@posts = @posts.try(:first, counts)
@posts.each do |post|
fb_post = NewsFeed.where(title: "Social-Facebook", category: 0, description: post[‘message’], url: post[‘link’], created_at: post[‘created_time’], updated_at: post[‘created_time’]).first_or_initialize
if fb_post.new_record?
fb_post.save
end
end
rescue
next
end
end
end
[/code]