I have the following code in a script tag in my HTML page:
window.fbAsyncInit = function () {
if (FB != null) {
FB.init({
appId: 'myAppID',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.getLoginStatus(function (response) {
console.log("callback");
}, true);
}
};
(function () {
var e = document.createElement('script'); e.async = true;
var protocol = "http:";
if (document.location.protocol == "https:")
protocol = "https:";
e.src = protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
The page is loaded in an Android WebView from a domain matching the registered one in FB's app settings.
For no apparent reason, the callback no longer fires. It worked just yesterday, but today it doesn't work, without me changing any code or app setting.
I placed a console.log() call before the getLoginStatus call, and it seems that the call itself is reached and executed; also I can see that some files are loaded from static.ak.facebook.com. It's just that the callback isn't called.
The application is not in a Sandboxed mode, which seemed to have caused this behavior for others.
I should also mention that the same code works perfectly in a standalone browser (desktop & mobile).
What gives?
Related
Facebook comments component load same JavaScripts many times and slows our page with 1.2+seconds sometimes load for 29sec
Please help.
the script is in the bottom of the HTML source, we get it from Facebook developer API
http://www.247polls.com/polls/should-marijuana-be-legalized/
FB.XFBML.parse();
Will load your comments even if the page loading has not been completed:
<script>
window.fbAsyncInit = function () {
FB.init({appId: 'YOUR-APP-ID', version: 2.4, xfbml: true});
if (typeof facebookInit == 'function') {
facebookInit();
}
};
(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 facebookInit() {
console.log('Loading comments...');
FB.XFBML.parse();
}
</script>
Another thing to improve the speed is limiting the count of comments to show with num_posts to 5.
Keep rocking!
add js.async=true; and make sure you follow this doc :
https://developers.facebook.com/docs/plugins/comments/
ref: https://geekflare.com/load-facebook-like-and-share-button-faster/
My website is using Facebook Connect, but since a month it's not working. I suspect that Facebook changed something. I tried to find out, but it was impossible. I have a Java file that initiates the authentication, but I don't know if that file is the problem. Well, basically it connect, but it's not returning the registration form of my website.
window.fbAsyncInit = function() {
FB.init({appId: cfg_facebook_app_id, status: true, cookie: true, xfbml: true});
//initial login check
FB.getLoginStatus(function(response) {
if (response.session) {
//logged in, force logout
FB.logout(function() {
//logged out, subscribe to events
loginEvents();
});
} else {
//not logged in
loginEvents();
}
});
function loginEvents() {
FB.Event.subscribe('auth.logout', function(response) {
// do something with response
logout();
});
FB.Event.subscribe('auth.login', function(response) {
login(response);
//login redirects the user. Before logout fires()
});
}
};
(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);
}());
function login(){
FB.api('/me', function(response) {
window.location = cfg_site_url + 'facebook_auth.php?hashcode='+response.id;
});
}
try{} updating to the new version of javascript sdk https://developers.facebook.com/docs/reference/javascript/
As of December 13th, 2011, the JavaScript SDK now only supports OAuth
2.0 for authentication. The ability to enable OAuth 2.0 in the JS SDK was first introduced in July. All apps were given until October 1,
2011 to test and migrate. With this change, please ensure that you are
using FB.getAuthResponse to obtain the access token.
I have a simple site, I want to code that when ever a user on my site Like my Page which is embeded in it another button should appear below it saying "Proceed to Next Step"
Hope so you got my idea.
So, in essence, you have to use the FB API to achieve what you want. Here is the example:
$(document).ready(function()
{
window.fbAsyncInit = function() {
FB.init({ status: true, cookie: true, xfbml: true });
FB.Event.subscribe('edge.create', function(href, widget)
{
//Liked event - do something here
$('#something').show();
});
};
(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);
}());
});
I was reading facebook javascript SDK when I saw the following syntaxt that I don't understand:
(function(){...}());
Does anyone know what does it do?
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'your 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);
}());
</script>
it's an anonymous function, that gets called immediately after its declaration. It's used to create local variables without clobbering up the global scope. the variable e will not be visible nor accessible outside the function block
I'm trying to switch over to the new Facebook JavaScript SDK from the old JavaScript library (where I was using Connect) and I'm unable to get the permission dialog to appear. I'm trying to get the permission dialog that's shown under the "Data Permissions" section here.
My old call was this (with appropriate initialization):
FB.Connect.showPermissionDialog('publish_stream');
I tried changing to this (again, with appropriate initialization) but it's not working, it runs without error but the callback is never run:
FB.login(function(response)
{
if (response.session)
{
if (response.perms)
{
alert('user is logged in and granted some permissions: ' + response.perms);
}
else
{
alert('logged in but didnt grant permissions');
}
}
else
{
alert('not logged in');
}
},
{perms:'publish_stream'});
This is the initialization code I'm using:
window.fbAsyncInit = function()
{
FB.init({appId: 'xxxxxxxx', 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);
}());
After MUCH tinkering around with the code trying to get this to work I finally found out where the error was. The JavaScript code needs to be place at the end of the HTML, near the </body> tag. I moved it there and everything worked!