Skip to content

Instantly share code, notes, and snippets.

@adamloving
Created May 26, 2014 23:06
Show Gist options
  • Save adamloving/bd86745c102f67ea1cab to your computer and use it in GitHub Desktop.
Save adamloving/bd86745c102f67ea1cab to your computer and use it in GitHub Desktop.
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