0

Rails 앱에서 Facebook API를 구현했습니다. 우리는 Facebook 페이지를 가지고 있는데, 사용자가 레일스 앱에 무언가를 게시 할 때 자동으로 상태를 게시해야합니다. 문제는 자동으로 Facebook 액세스 토큰을 갱신해야한다는 것입니다. 나는 이런 식으로 일을하려고하고 있어요,하지만 난 그것을 처음을하고있는 중이 야, 나는 조금 여기 손실입니다 :Rails + Facebook : Facebook 액세스 토큰을 갱신하는 방법은 무엇입니까?

Processing by ListingsController#post_to_fb as HTML 
Completed 500 Internal Server Error in 1015ms 

OpenURI::HTTPError (400 Bad Request): 
    app/controllers/listings_controller.rb:194:in `fb_autopost' 
:

def fb_autopost  
    require 'net/http' 
    temp_token = 'my_short_time_token' 


    app_id = '145634995501123' # I didn't put here real token from obvious reason 
    app_secret = '0dd5fcf93b4280fb19bf6b80f487c123' # I didn't put here real token from obvious reason 
    puts "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}&client_secret=#{app_secret}&grant_type=fb_exchange_token&fb_exchange_token=#{temp_token}" 
    puts '---' 
    url = "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}&client_secret=#{app_secret}&grant_type=fb_exchange_token&fb_exchange_token=#{temp_token}" 
    response = open(url) 
    puts response.inspect 
    puts '---' 
    end 

이 코드를 실행하면, 나는이 오류

토큰을 갱신하는 방법에 대해 도움을 요청합니다. 이 경우 데이터베이스에 토큰을 저장하고이 작업을 실행하고 토큰을 갱신하기 위해 만료되기 하루 전과 같은 가장 좋은 방법입니까? 또는 더 좋은 방법이 있습니까?

당신에게 너무 감사

나는 개인적으로이 보석 사용
+0

에 한번 사용 Omniauth 페이스 북이 더 easelly 단지 sugestion

당신은 문서에 필요한 모든 것을 찾을 수 있어야입니다 = 디. – overallduka

+0

거기에 액세스 토큰을 갱신하는 것과 동일한 문제가 발생합니다. – user984621

답변