Facebook Feed Dialog disappearing
I'm experiencing an odd behavior. I'm using Facebook's feed dialog javascript (FB.ui). 开发者_Python百科It was working a week ago, but now it's not. When I click on a button, the Facebook window shows up, but after loading for a little time, it automatically disappears without any error messages. Any ideas? Here's my code below:
HTML:
<a href="#" class="button" id="fb-request">Share with friends</a>
JavaScript:
$("#fb-request").click(function () {
FB.ui({
method: 'feed',
name: 'Check out website',
link: 'http://www.website.com',
picture: 'http://website.com/f8.jpg',
caption: 'A website.',
description: 'website.',
message: 'website'
},
function (response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
});
I just tested this and it worked with no problem. Are you getting any errors in your javascript console window? Are you calling FB.init with your appId? And is the page being accessed from the domain/url specified on the Facebook app settings? Do you have a div with an id of "fb-root" on your page? Are you putting that jquery call inside a document.ready function? Have you tried with a different app id to make sure your current app id hasn't been blacklisted for spamming?
My test that worked:
<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
<a href="#" class="button" id="fb-request">Share with friends</a>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId : '**yourAppId**', status : true, cookie : true, xfbml : true });
$(document).ready(function() {
$("#fb-request").click(function () {
FB.ui({
method: 'feed',
name: 'Check out website',
link: 'http://www.website.com',
picture: 'http://website.com/f8.jpg',
caption: 'A website.',
description: 'website.',
message: 'website'
},
function (response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
});
});
</script>
</body>
</html>
It turns out in recent weeks, Facebook introduced a CSS class="loading" in the FB.ui dialogs. It conflicted with our own "loading" class in CSS. After 10+ hours of debugging, we were finally able to fix it. Great job FB. ;-(
精彩评论