Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created March 3, 2014 11:37
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save emad-elsaid/9323267 to your computer and use it in GitHub Desktop.
Save emad-elsaid/9323267 to your computer and use it in GitHub Desktop.
posting to facebook groups all at once with ruby posting to facebook groups all at once with ruby
#!/usr/bin/env ruby
require 'koala' # gem install koala --no-ri --no-rdoc
# create a facebook app and get access token from here
# https://developers.facebook.com/tools/explorer
# select "groups", "photos" when authenticating
oauth_access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
group_filtering_words = ['ruby']
image_path = 'image.png' #change to your image path
message = 'My Cool image.' # your message
graph = Koala::Facebook::API.new(oauth_access_token)
# getting groups of interest
groups = graph.get_connections("me", "groups").select do |group|
group_filtering_words.any? do |word|
group["name"].downcase.include? word
end
end
index = 0
groups.each do |group|
index += 1
puts "[#{index}/#{groups.size}] Posting to group #{group["name"]}."
graph.put_picture(
image_path,
{:message => message},
group['id']
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment