Logging my rails application's users into facebook through iframe display option hangs
This code does not work:
$(document).ready(function() {
window.fbAsyncInit = function() {
FB.init({appId: "<%= FACEBOOK_CONFIG['application_id'] %>", status: true, cook开发者_开发技巧ie: true,
xfbml: true});
FB.ui(
{
method: 'oauth',
client_id: "<%= FACEBOOK_CONFIG['application_id'] %>",
scope: "<%= FACEBOOK_CONFIG['permissions'] %>",
state: "<%= secure_hash(FACEBOOK_CONFIG['secret_phrase']) %>"
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
});
What am I doing wrong?
You've done the FB.init({appId: ..., xfbml: true}); bit first right?
I think the method you want to call is {method: 'oauth'} like:
FB.ui({ method: 'oauth',
client_id: <%= FACEBOOK_CONFIG['application_id'] %>,
scope: '<%= FACEBOOK_CONFIG['permissions'] %>',
state: '<%= secure_hash(FACEBOOK_CONFIG['secret_phrase']) %>'
},
function (response) {
if (response && response.post_id) {
alert('success');
} else {
alert('failure');
}
}
);
Although, to just do a login it's easier to call:
FB.getLoginStatus(function(response) {
if (response.session) { alert('success'); }
else { alert('nope'); }
});
精彩评论