ユーザーが Koala gem を使用してアップロードしたビデオを Facebook アプリ ウォールに投稿しようとしています。
を使用してビデオを投稿しようとすると
put_connections("APP_ID", "APP_NAME:upload", video: "VIDEO_FILE")
次のエラーが表示されます。
OAuthException: (#240) Requires a valid user is specified (either via the session or via the API parameter for specifying the user.
ここに私のファイルがあります:
ビデオ controller.rb
class VideosController < ApplicationController
def index
@videos = Video.all
end
def new
@video = Video.new
end
def show
@video = Video.find params[:id]
end
def upload
@video = Video.create params[:video]
if @video
@upload_info = save_video_new_video_url(video_id: @video.id)
else
render "/videos/new"
end
end
def save_video
@video = Video.find params[:id]
if params[:id]
Video.begin_upload current_user.id, params[:file]
else
Video.delete_video @video
end
redirect_to videos_path, :notice => "video successfully uploaded"
end
end
video.rb
class Video < ActiveRecord::Base
scope :completes, where(:is_complete => true)
scope :incompletes, where(:is_complete => false)
def self.begin_upload user_id, video_file
user = User.find user_id
video = user.facebook.put_connections(FB_CONFIG['app_id'], "thecomfortmovement:upload", video: File.expand_path(video_file.tempfile.to_path.to_s))
end
def self.delete_incomplete_videos
self.incompletes.map{|r| r.destroy}
end
def self.delete_video video
vid = Video.find video
vid.destroy
end
end
このスクリーンキャストに見られるように、ユーザーを認証するために omniauth-facebook gem を使用しています: http://railscasts.com/episodes/360-facebook-authentication
このエラーが発生する理由を知っている人はいますか? 私は間違いなくまだログインしているので、セッションと oauth トークンがまだ有効であることを意味するはずです。助言がありますか?
アップデート
ここに私のユーザーモデルがあります
class User < ActiveRecord::Base
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.email = auth.info.email
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
def facebook
@facebook ||= Koala::Facebook::API.new(oauth_token)
end
end
更新 2
これは、セッションの設定と削除に使用するコントローラーです。
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_url
end
def destroy
session[:user_id] = nil
redirect_to root_url
end
end