Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Post several links to a Facebookpage
#!/usr/bin/env ruby
# foreman run script/social/auto-fbpost.rb data/crawl-data.json
# To get page access token, go to graph explorer, get user token with manage_pages and publish_actions permission,
# then request /{userId}/accounts
require 'koala'
require 'json'
graph = Koala::Facebook::API.new(ENV['FB_PAGE_ACCESS_TOKEN'])
urls = JSON.parse(File.open(ARGV.first).read)
# todo: add hashtags
for url in urls[2..100]
text = url['description'] || url['title']
graph.put_object(ENV['FB_PAGE_ID'], 'feed', :message => text, :link => url['url'])
puts "Posted: #{text}"
Kernel.sleep(10)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment