facebook plugins not refreshing together - facebook

i have two Facebook plugins(like and comment box) on my page.
when i login with on plugin it not logins another plugin automatically until i refresh page.
for example : when i login by clicking on like button,my comment box remains in logout state until i refresh page.
please suggest me something good for that problem
my code is as follow
<script>
window.fbAsyncInit = function () {
FB.init({ appId: 'My app ID', status: true, cookie: true, xfbml: true });
FB.Event.subscribe("xfbml.render", function (targetUrl) {
$("#myh1").html("Facebook Loaded");
//alert('edge.create');
setTimeout(aaa, 500);
});
FB.Canvas.setDoneLoading(function () {
alert("Done loading");
});
FB.Event.subscribe('comment.remove', function (response) {
alert('The status of the session is: ' + response.status);
});
};
(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);
} ());
function aaa() {
$("#content_1").mCustomScrollbar({
scrollButtons: {
enable: false
}
});
}
</script>
<div class="fb-like" data-send="false" data-href="http://www.facebook.com /AiLiveCaptions" data-width="298" data-show-faces="true">
</div>
<div class="fb-comments" data-href="http://www.facebook.com/AiLiveCaptions" data-num- posts="8" order_by="reverse_time" data-width="280"></div>

You can use
FB.XFBML.parse();
to render XFBML markup in a document on the fly.
FB Documentation

Related

How Can I Capture an Event When I Login / Logout from Facebook Comment Box?

Is there any way to capture a Facebook event when I login or logout from any Facebook social plugin, like comment box or like button? I want to refresh my page whenever a user logins into a Facebook plugin. Because when I login with comment box it doesn't show that I am logged in and so I can't use the "Like" button. But when I refresh my page it shows I am logged in to both plugins.
Here is my code:
<div id="fb-root">
</div>
<script>
window.fbAsyncInit = function () {
FB.init({ appId: 'My App ID', status: true, cookie: true, xfbml: false });
setTimeout(aaa, 6000);
FB.Event.subscribe("xfbml.render", function (targetUrl) {
$("#myh1").html("Facebook Loaded");
alert('edge.create');
});
FB.Event.subscribe('auth.authResponseChange', function (response) {
alert('The status of the session is: ' + response.status);
});
};
(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);
} ());
function aaa() {
FB.XFBML.parse(document.getElementById('fbDiv'), function () {
alert('I rendered');
});
}
</script>
<div id="fbDiv">
<div class="fb-comments" data-href="http://www.facebook.com/AiLiveCaptions" data-num-posts="2" data-width="470">
</div>
</div>
the way i see it, this could be the default behaviour when you are using two separate plugins weather they are of facebook or any third party website i.e.facepile/commentbox.
your browser needs to reload in order to update the session on page across multiple plugins on same page, just like the difference when you are open any mail id across multiple tabs with opening same id on different browsers.

FB-Connect simple script not working

<html xmlns="http://www.w3.og/1999/xhtml" xmlns:fb="http://facebook/2008/fbml">
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
<fb:login-button onlogin="update_user_box();"></fb:login-button>
<script>
function update_user_box(){
user_box = document.getElementById("user");
user_box.InnerHtml = "<span>"
+"<fb:profile-pic uid='loggedinuser' facebook-logo=true></fb:profile-pic>"
FB.XFBML.Host.parseDomTree();
}
FB.init("APP_ID","xd_reciever.htm");
</script>
<div id="user"></div>
This is my script. Actually i want to fetch the profile picture of logged in user from facebook connect. But this is not working, I got this script from http://mashable.com/2008/12/11/facebook-connect-blog/ and i can't find what's my error. How to get it correct to work like-what i want?
This should work for you...
// assume we are already logged in
FB.init({appId: 'YOUR_APP_ID', xfbml: true, cookie: true});
function showProfile(response) {
if (response.authResponse) {
//user is already logged in and connected
var userInfo = document.getElementById('user');
FB.api('/me', function(response) {
userInfo.innerHTML = '<img src="https://graph.facebook.com/' + response.id + '/picture">' + response.name;
});
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(showProfile);
FB.Event.subscribe('auth.statusChange', showProfile);
(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);
}());
Then have two div's for the login button and for storing the profile info.
<div class="fb-login-button" autologoutlink="true"></div>
<div id="user"></div>

Facebook "FB.Canvas.getPageInfo", how to use it properly

I need help figuring out how to appropriately use the FB.Canvas.getPageInfo from Facebook's javascript sdk:
https://developers.facebook.com/docs/reference/javascript/FB.Canvas.getPageInfo/
I'm able to get the info and log/alert the data:
function getFbCanvasInfo() {
FB.Canvas.getPageInfo(function(fbCanvasInfoObject) {
console.log(fbCanvasInfoObject);
});
}
$("a.GetScrollTest").live( "click", function() {
getFbCanvasInfo();
return false;
});
But I can't figure out how to set that data and then apply it to other elements or functions (i.e. like something below):
$("a#test-link").each(function() {
var fbPosition = getFbCanvasInfo().scrollTop;
$(this).append("<em>The scroll top value is " + fbPosition + "px");
}
I know its not right and I'm missing something here.
BTW these functions are all below my async init and FB root, which appears like so:
<div id="fb-root"></div>
<script type="text/javascript">//<!--
window.fbAsyncInit = function()
{
FB.init({
appId: '223615011031939',
status: true,
cookie: true,
xfbml: true,
oauth:true,
channelUrl: '[MY PROJECTS CHANNEL URL]'
});
var isLoaded = true;FB.Canvas.setSize();FB.Canvas.setAutoGrow(500);
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
;(function($){
$(document).ready(function($){
[THE JQUERY FROM ABOVE HERE]
});
})(jQuery);
//--></script>
Much appreciation to anyone who has advice/expertise! Thanks!
The getPageInfo returns a readonly object. To "set" things, you would need to use the provided setter functions listed in the documentation. One of them to set the size of the canvas is setSize see https://developers.facebook.com/docs/reference/javascript/FB.Canvas.setSize/
Also you should cleanup your javascript so the async nature of working with their API is good.
$("a.GetScrollTest").live( "click", function() {
FB.Canvas.getPageInfo(function(fbCanvasInfoObject) {
var fbPosition = fbCanvasInfoObject.scrollTop;
$(this).append("<em>The scroll top value is " + fbPosition + "px");
});
return false;
});

Apprequests from a Website

Is there any way to send apprequests if your application is a website?
I reported a bug on facebook http://developers.facebook.com/bugs/182553325173000 but I do not know if this is possible or not
yes you can do this by adding the JS API,
before <body> add:
<script type="text/javascript">
function inviteFriends(){
var receiverUserIds = FB.ui({
method : 'apprequests',
message: 'YOUR CUSTOM MESSAGE',
},
function(receiverUserIds) {
console.log("IDS : " + receiverUserIds.request_ids);
}
);
}
</script>
after the <body> include the API (asynchronous method):
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true //enables OAuth 2.0
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
and call it:
or
You can do that with the Javascript SDK
it is in the documentation:
https://developers.facebook.com/docs/reference/dialogs/requests/
It's possible, as the other answers have shown, but the user will be brought to your canvas app when they accept the requests

Facebook Graph API: FB.login() called before calling FB.init()

I'm trying to use the new Facebook Graph API on my website. This is what I have:
Somewhere on the page:
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
Right after the tag:
<div id="fb-root">
</div>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({ appId: '<%= ConfigurationManager.AppSettings["FBAppId"] %>', status: true, cookie: true, xfbml: true });
/* All the events registered */
FB.Event.subscribe('auth.login', function (response) {
// do something with response
alert("login success");
});
FB.Event.subscribe('auth.logout', function (response) {
// do something with response
alert("logout success");
});
FB.getLoginStatus(function (response) {
if (response.session) {
// logged in and connected user, someone you know
alert("login success");
}
});
};
(function () {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
} ());
</script>
but when I click on the generated login button, nothing happens.
In addition, I'm getting
FB.getLoginStatus() called before calling FB.init().
in Firebug console.
Any ideas?
I can't believe it, I was referencing a non existing key in the Web.config hence FB.init was failing silently.
It works as expected now.
To be clearer I wasn't passing the appId to FB.init, once I did, it worked.
Had the same issue, here is the solution that worked for me. Just put the following in your head section or in other words, add the app_id to the source of the facebook js.
<script src="//connect.facebook.net/en_US/all.js&appId=xxxxxxxxxxxxxxx" type="text/javascript"></script>
In my case, the problem went away after I disabled the XFBML functionality (i.e. setting the xfbml key to false, removing the fb: namespace and the #xfbml=1 fragment in <script src="…">). Good that I didn’t need it anyway.
YMMV, there are several other valid reasons why this error message can appear.