2011-01-24 6 views
2

Kの連中をOAuthのトーク​​ンを格納することはできませんので、私はdialybooth APIを使用してworkign、およびOAauthので、最初、私はまっすぐは、セッション中に(レール)

#first redirect the user to the authorize_url 
    redirect_to dailybooth.authorize_url 

#on user return grab the code from the query string 
dailybooth.oauth_token(params[:code]) 

#make request to the api 
pp dailybooth.get('/users.json') 

問題は、それが一定のリダイレクトだろう、だったので、持っていたましたoauth_tokenが設定されているかどうかをチェックしていないので、私はこれを行いました。さて、これはユーザーが許可、dailybooth認可ページに私を送って、その事があればある、(ユーザー情報の配列が返されました)私のページに送られ、私は自分のアカウントへのアクセスを得た

unless dailybooth.oauth_token(params[:code]) 
#first redirect the user to the authorize_url 
redirect_to dailybooth.authorize_url 

#on user return grab the code from the query string 
dailybooth.oauth_token(params[:code]) 
end 


#make request to the api 
pp dailybooth.get('/users.json') 

あなたはトークンがもう存在しなかったことをリフレッシュし、ユーザーは再認証する必要がありました。セッションでoauth_tokenを保存するためにだった私が試しだから何

if session[:oauth_code] #If session is set 
    dailybooth.oauth_token(session[:oauth_code]) #sign in using cookie 
else 
    if params[:code] 
    @oauth_token_ = params[:code] 
    session[:oauth_code] = @oauth_token_ 
    else 
     #first redirect the user to the authorize_url 
     redirect_to dailybooth.authorize_url 
    end 
end 



#make request to the api 
@info = dailybooth.get('/users.json') 

if @info['error']  
    if @info['error']['error_code'] 
    if @info['error']['error_code'] == 302 #if getting invalid token, request another token. 
     session[:oauth_code] = nil 
     #first redirect the user to the authorize_url 
     redirect_to dailybooth.authorize_url 

    end 
    end 
end 

私が最初に私のウェブサイトに行くとき、私はまだ、同じことを得ている、と私は認証ページにリダイレクトしています私はそのアカウントにアクセスしますが、インデックスに戻ると、oauth_tokenが無効であると表示されます。どんな助け?

答えて

0

私は正直言って100%確信しているわけではありません。(そしてDailyBoothのAPIドキュメントは...欠けているとは言えませんが) "トークン" params[:code]から取得して@oauth_token_に格納する)アクセストークンを取得し、アクセストークンを格納します(たとえば、オブジェクト/配列の場合は結果フォームdailybooth.oauth_token(session[:oauth_code])、または少なくともその一部を格納します)。

unless session[:oauth_code] #unless the session is set 
    if params[:code] 
    session[:oauth_code] = dailybooth.oauth_token(params[:code]) 
    else 
    #first redirect the user to the authorize_url 
    redirect_to dailybooth.authorize_url 
    end 
end 

#make request to the api 
@info = dailybooth.get('/users.json') 

if @info['error']  
    if @info['error']['error_code'] 
    if @info['error']['error_code'] == 302 #if getting invalid token, request another token. 
     session[:oauth_code] = nil 
     #first redirect the user to the authorize_url 
     redirect_to dailybooth.authorize_url 

    end 
    end 
end 

これはあなたが正しい方向を指していることを希望します。