我阅读了 Facebook Graph API 上的文档,但对此感到困惑
我的代码如下
路线.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'] = ''
学生.rb
def facebook
@fb_user ||= FbGraph::User.me(self.services.find_by_provider('facebook').token)
end
文章控制器.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')
架构.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.