2014-01-09 2 views
5

Я хочу опубликовать несколько фотографий в моей группе facebook с помощью Koala # put_connection или более конкретных методов, таких как #put_picture. Пример одного изображения проводки:Опубликовать несколько фотографий с Koala :: Facebook :: GraphAPIMethods # put_connections

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

у кого есть идеи? Благодаря

+0

Позвольте мне знать, ниже решение работал или нет –

ответ

0

Попробуйте этот код

#!/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 
Смежные вопросы