ruby-on-rails - Heroku 的 Facebook Canvas 应用教程 : oath error

标签 ruby-on-rails ruby sinatra omniauth facebook-canvas

我正在复制并粘贴 Heroku 教程中关于构建 Canvas 应用程序以在 Heroku 上托管的代码(参见此处)。 https://devcenter.heroku.com/articles/facebook-ruby但是,我收到了回溯(见下文)所说的与 omniauth 相关的错误。

谁能解释一下

NoMethodError at /
undefined method `include?' for nil:NilClass
file: builder.rb location: call line: 29

这些是它使用的 gem

gem 'sinatra', '1.0'
gem 'oa-oauth', '0.1.6'



BACKTRACE
(condense)
JUMP TO: GET POST COOKIES ENV
/Users/michael/.rvm/gems/ruby-1.9.3-rc1@ruby193/gems/oa-core-0.1.6/lib/omniauth/builder.rb in call
      @ins << @app unless @ins.include?(@app)
/Users/michael/.rvm/gems/ruby-1.9.3-rc1@ruby193/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb in call
        status, headers, body = @app.call(env)
/Users/michael/.rvm/gems/ruby-1.9.3-rc1@ruby193/gems/rack-protection-1.2.0/lib/rack/protection/base.rb in call
        result or app.call(env)
/Users/michael/.rvm/gems/ruby-1.9.3-rc1@ruby193/gems/rack-protection-1.2.0/lib/rack/protection/base.rb in call
        result or app.call(env)
/Users/michael/.rvm/gems/ruby-1.9.3-rc1@ruby193/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb in call

主要代码

索引.erb

<%=session['fb_error']%>

<% if session['fb_auth'] %>
  <a href='logout'><img src='images/fb_logout_button.png'></a>
<% else %>
  <a href='auth/facebook'><img src='images/fb_login_button.png'></a>
<% end %>

<h3><%= 'Hello, ' + session['fb_auth']['user_info']['first_name'] + ', ' if session['fb_token'] %>Welcome to my list of interesting articles.</h3>

<table>
  <% @articles.each do |article| %>
  <tr>
    <td class='article'>- <a href='<%=article[:url]%>' target='_blank'><%=article[:title]%></a></td>
    <td>
      <% if session['fb_auth'] %>
        <iframe src="http://www.facebook.com/plugins/like.php?href=<%=article[:url]%>&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>
      <% end %>
    </td>
  </tr>
  <% end %>
</table>

<% if session['fb_auth'] %>
  <hr />
  <p><span class='like_site'>Do you like this site?</span></p>
  <p><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffaceboku.heroku.com%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe></p>
<% end %>

Facebook.rb

equire 'sinatra'
require 'omniauth/oauth'

enable :sessions


#Here you have to put your own Application ID and Secret
APP_ID = "495940167082961"
APP_SECRET = "686da25c0fdd04a6f61b287bb0d5c9aa"

use OmniAuth::Builder do
  provider :facebook, APP_ID, APP_SECRET, { :scope => 'email, status_update, publish_stream' }
end

get '/' do
    @articles = []
    @articles << {:title => 'Deploying Rack-based apps in Heroku', :url => 'http://docs.heroku.com/rack'}
    @articles << {:title => 'Learn Ruby in twenty minutes', :url => 'http://www.ruby-lang.org/en/documentation/quickstart/'}

    erb :index
end

get '/auth/facebook/callback' do
  session['fb_auth'] = request.env['omniauth.auth']
  session['fb_token'] = session['fb_auth']['credentials']['token']
  session['fb_error'] = nil
  redirect '/'
end

get '/auth/failure' do
  clear_session
  session['fb_error'] = 'In order to use this site you must allow us access to your Facebook data<br />'
  redirect '/'
end

get '/logout' do
  clear_session
  redirect '/'
end

def clear_session
  session['fb_auth'] = nil
  session['fb_token'] = nil
  session['fb_error'] = nil
end

最佳答案

从评论中复制答案以便从“未回答”过滤器中删除此问题:

Hey, guys, I wrote that tutorial ... I've updated the tuto and the code, everything seems to be working now, please, let me know if it doesn't. it doesn't show some images because I need to wait for Heroku's approval but it works anyways: https://devcenter.heroku.com/articles/facebook-ruby

~ 根据 raf 回答

关于ruby-on-rails - Heroku 的 Facebook Canvas 应用教程 : oath error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12409890/

相关文章:

mysql - 有没有其他库可以用来在 Ruby 中连接 MySQL?

ruby - Sinatra erb 文件中所有 View 的变量

ruby - 如何在 Padrino 应用程序中安装 Sinatra 应用程序?

ruby - 无法从同一网络上的另一台计算机访问本地 Sinatra 服务器

ruby-on-rails - 操作系统 : Rails Layer connect to Elasticache : Redis

ruby-on-rails - 如何检查 Rails rich_text_field( Action 文本)是否为空白?

ruby-on-rails - 当我从未使用过 mongodb 时,Rails App 尝试使用 mongodb

ruby-on-rails - 简单 - 使用 String#scan 提取电子邮件地址

ruby-on-rails - 为什么我必须将我的私钥上传到我的服务器才能让 Capistrano 与 GitHub 一起工作?

ruby - 在 ruby​​ 函数调用中,逻辑运算符之前是否必须使用括号?