FbGraph InvalidRequest

时间:2012-04-12 08:55:01

标签: facebook-graph-api

我在Facebook Graph API上阅读了文档,但我对此感到困惑

about permissions

about expired access token

我的代码关注

的routes.rb

  match '/auth/:provider/callback' => 'services#create'

services_controller.rb

            if service_route == 'facebook'
            omniauth['info']['email'] ? email =  omniauth['info']['email'] : email = ''
            omniauth['info']['name'] ? name =  omniauth['info']['name'] : name = ''
            omniauth['uid'] ?  uid =  omniauth['uid'] : uid = ''
            omniauth['provider'] ? provider =  omniauth['provider'] : provider = ''
            omniauth['credentials']['token'] ? session['fb_access_token'] =  omniauth['credentials']['token'] : session['fb_access_token'] = ''

student.rb

 def facebook
    @fb_user ||= FbGraph::User.me(self.services.find_by_provider('facebook').token)
 end

articles_controller.rb

    def create

    @article = current_student.articles.new(params[:article])
    respond_to do |format|
        if @article.save
            format.html { redirect_to(@article, :notice => 'Το άρθρο δημιουργήθηκε επιτυχώς.') }
            format.xml  { render :xml => @article, :status => :created, :location => @article }


            current_student.facebook.feed!(
                :message => 'Hello, Facebook!',
                :name => 'My Rails 3 App with Omniauth, Devise and FB_graph')

schema.rb

  create_table "services", :force => true do |t|
    t.integer  "student_id"
    t.string   "provider"
    t.string   "uid"
    t.string   "uname"
    t.string   "uemail"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "token

并且在创建文章时我最终解决了这个问题

   FbGraph::InvalidRequest in ArticlesController#create

   OAuthException :: An active access token must be used to query information about the current user.

1 个答案:

答案 0 :(得分:0)

最后代码是对的。只缺少

service.rb

  attr_accessible :provider, :uid, :uname, :uemail, :token

一切都很好