2

我有一个在 Facebook 上自动发布数据的简单操作,它是这样的:

pages = FbGraph::User.me(temp_token).accounts
page = pages.detect do |page|
  if page.identifier == my_page
    page.feed!(
      :message => "a title",
      :link => 'a link',
      :description => "a description",
      :picture => 'an image'
    )
  end
  break
end

我正在考虑如何获得新令牌 - 我尝试过这样的事情:

require 'net/http'
temp_token = 'the current access token'

looky_co_app_id = 'APP_ID'
looky_co_app_secret = 'APP_SECRET'
puts "https://graph.facebook.com/oauth/access_token?client_id=#{looky_co_app_id}&client_secret=#{looky_co_app_secret}&grant_type=fb_exchange_token&fb_exchange_token=#{temp_token}"
url = URI.parse("https://graph.facebook.com/oauth/access_token?client_id=#{looky_co_app_id}&client_secret=#{looky_co_app_secret}&grant_type=fb_exchange_token&fb_exchange_token=#{temp_token}")
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
  http.request(req)
}
puts res.body

但我得到这样的错误:

Errno::ECONNRESET in my_controller_name#the_action

Connection reset by peer

我不确定我是否做得对,但如何正确更新访问令牌?

4

0 回答 0