はじめに
前回は、
第4回で作成したアプリのソースを元に、
今回のアプリのサンプルは、
rest-graphを用いた認証
第4回で、
今回は、
該当のコミットは、
include RestGraph::RailsUtil
before_filter :filter_setup_rest_graph, :set_current_user
helper_method :current_user
private
def filter_setup_rest_graph
rest_graph_setup(:auto_authorize => true, :write_cookies => true)
end
def set_current_user
@current_user = User.find_or_create_by_rest_graph!(rest_graph)
end
def current_user
@current_user
end
include RestGraph::RailsUtil を実行することによりincludeしたコントローラでRestGraphの提供するRailsのコントローラ向けのユーティリティーメソッドが利用できるようになります。
rest_
その後、
もう1つのポイントとして、
module EnvDefaults
def default_app_id
ENV["FACEBOOK_APP_ID"]
end
def default_secret
ENV["FACEBOOK_APP_SECRET"]
end
end
RestGraph.send(:extend, EnvDefaults)
このように実装することで、
パーミッション(権限)の追加
今回実装したいのは、
Facebookでは、
では、
#fb-root
:javascript
window.fbAsyncInit = function() {
FB.init({appId: '#{RestGraph.default_app_id}', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
このようにFacebookが提供しているjavascriptファイルを読み込んで、
次に、
$(document).ready(
function(){
$("#amazon-items").find('.post input').click(
function(){
var $this = $(this);
FB.login(function(response){
if (response.perms) {
$this.parents("form").submit();
} else {
alert('You must allow to access Facebook data from manga-dojo.');
}
},
{ perms: 'publish_stream, offline_access' }
);
return false;
}
);
}
);
登録ボタンが押された際に、

このようにして、
投稿処理
最後に、
def post_feed(options = {})
logger.debug "[POST/feed] #{options.inspect}"
self.client.post("me/feed", options) unless mock?
end
def client
@client ||= RestGraph.new(:access_token => self.oauth_token)
end
このように、
まとめ
今回は、
今回の当初の実装上でAmazonやFacebookのAPIのレスポンスの遅さなどがあり、
次回は、