【问题标题】:Post multiple pictures with Koala::Facebook::GraphAPIMethods#put_connections使用 Koala::Facebook::GraphAPIMethods#put_connections 发布多张图片
【发布时间】:2014-01-27 16:59:49
【问题描述】:

我想使用 Koala#put_connection 或更具体的方法(如 #put_picture)将多张图片发布到我的 Facebook 群组。 单张图片发布示例:

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

有人有想法吗?谢谢

【问题讨论】:

  • 让我知道以下解决方案是否有效

标签: ruby-on-rails koala


【解决方案1】:

试试这个代码

#!/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

【讨论】:

  • 如何请求权限?获取组列表的好权限名称是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-15
  • 1970-01-01
  • 1970-01-01
  • 2017-04-06
  • 1970-01-01
相关资源
最近更新 更多