Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post multiple pictures with Koala::Facebook::GraphAPIMethods#put_connections

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

like image 320
lPotatoes Avatar asked Jan 09 '14 08:01

lPotatoes


People also ask

How do you post multiple pictures in one post on Facebook?

Posting Multiple Photos With the Facebook AppIn the status field at the top of the News Feed, tap Photo. Tap the thumbnails of the photos you want to add to the status. Use the Done button to open the preview screen. Add text to your status post, if you want, and select +Album from the options.

How do you post 3 pictures in a row on Facebook?

Use the Ctrl + Select combination to select multiple. Drag the selected photos to your Facebook. Drag them across the screen and drop them onto the text field where you write your post on the Facebook page.

What is a post with multiple pictures called?

You can share a post with up to 10 photos and videos as a single post, also known as a carousel, to your Instagram feed.


1 Answers

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
like image 190
Aniket Tiwari Avatar answered Oct 24 '22 00:10

Aniket Tiwari