Post multiple pictures with Koala::Facebook::GraphAPIMethods#put_connections
Asked Answered
L

1

6

I want to post multiple pictures to my facebook group with Koala#put_connection or more specific methods like #put_picture. Example of single picture posting:

graph = Koala::Facebook::API.new(token)
graph.put_picture("picture_url", {:message => "Message"}, "my_group_id")

Could anyone has an idea? Thanks

Loeffler answered 9/1, 2014 at 8:37 Comment(1)
Let me know the below solution worked or notNenitanenney
N
1

Try this code

#!/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
Nenitanenney answered 23/10, 2017 at 9:36 Comment(1)
how ask permission? what the good permission name to get list of groups?Halves

© 2022 - 2024 — McMap. All rights reserved.