FB.getLoginStatus() called before calling FB.init(). CRAZY - javascript

window.fbAsyncInit = function(){
FB.init({
appID : 'my app id is here',
channelUrl : '//myappname.herokuapp.com/channel.php',
status : true,
cookie : true,
xfbml : true,
frictionlessRequests: true
});
// Additional auth
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Ok so, that's my scripts.js file, and I HAVE included fb-root to my pagebody, for some reason when loading the page, its logging:
FB.getLoginStatus() called before calling FB.init().
Twice, in the call to all.js line 52, any ideas whats going on?

This is how i make it:
window.fbAsyncInit = function () {
if (FB.init) return;
// init the FB JS SDK
FB.init({
appId: 'your app ID', // App ID from the App
//channelUrl: '//' + window.location.hostname + '/channel.html',
//This to get the user details back from Facebook
//scope: 'id,name,gender,user_birthday,email', etc
status: true, // check the login status upon init?
cookie: true, // set sessions cookies to allow your server to access the session?
xfbml: true // parse XFBML tags on this page?
});
}
At the end of HTML Body...
<script>
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
</script>
...Or maybe you might use fb embeded iframe
Facebook Like Button Reference

Related

How do I fix "Uncaught ReferenceError: FB is not defined"?

When I run this code, in Google Chrome, it gives me the following error:
Uncaught ReferenceError: FB is not defined
I have read multiple other questions regarding the same error but none seem to have a solution for this.
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxx',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.2'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
FB.api(
'/me',
'GET',
{"fields":"id,name,posts{picture,message,comments{likes}}"},
function(response) {
// Insert your code here
}
);
I want the Facebook API to return the fields I have selected.
My code is a copy of the code shown in Facebook's documentation.
You cannot use FB before the JS SDK is initialized:
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxx',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.2'
});
FB.api(
'/me',
'GET',
{"fields":"id,name,posts{picture,message,comments{likes}}"},
function(response) {
console.log(response);
}
);
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Btw, this code will not work without user authorization. How to do that is explained in detail here: https://developers.facebook.com/docs/facebook-login/web/
There is also a full example in the docs: https://developers.facebook.com/docs/facebook-login/web/#example

facebook follow and like api subscription event code (edge.create not working)

I've implemented liking a website url along with attaching the edge.create event to it. I implemented the follow button but did not get the edge.create to function when clicking to follow button. Also, I cannot figure out how to like a specific facebook page and as well get the edge.create event to subscribe.
I have the following code for when a user performs a LIKE on our website (not the facebook page):
This code works well
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxx',
autoLogAppEvents : true,
xfbml : true,
version : 'v2.9'
});
FB.AppEvents.logPageView();
FB.Event.subscribe('edge.create', function(response) {
alert(1);
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
<div class="fb-like" data-href="https://www.facebook.com/fbpage" data-layout="standard" data-action="like" data-show-faces="true"/>
}
Here is my code for following a facebook page , which works but does not fire the edge.create code
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxx',
autoLogAppEvents : true,
xfbml : true,
version : 'v2.9'
});
FB.AppEvents.logPageView();
FB.Event.subscribe('edge.create', function(response) {
alert(1);
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
<div class="fb-follow" data-href="https://www.facebook.com/fbpage" data-layout="standard" data-size="small" data-show-faces="true"/>
As you can see, I need help getting the edge.create to function with clicking follow button and if possible a way to like a specific facebook page along with the edge.create event code.

Facebook Javascript SDK, how to know when async script has been loaded?

I do include facebook snippet like so
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'someAppId',
cookie : true,
xfbml : true,
version : 'v2.8'
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Then, somewhere in my code, i will be doing something like
FB.foo.bar();
How i know when the script has done loading and therefore the FB object does exists?
That is what window.fbAsyncInit is for, the JavaScript SDK is loaded when you hit that callback function. You can use FB right after FB.init.

How to use facebook login in parse.com backend on website?

I am trying to integrate parse database with my website. It is almost one day I spent but I couldn't figure out the problem. Here is my code:
<div id="fb-root"></div>
<script>
Parse.initialize("**************************", "**********************");
window.fbAsyncInit = function() {
Parse.FacebookUtils.init({
appId : '*****************',
cookie : true,
xfbml : true
});
Parse.FacebookUtils.logIn(null, {
success: function(user) {
if (!user.existed()) {
alert("User signed up and logged in through Facebook!");
} else {
alert("User logged in through Facebook!");
}
},
error: function(user, error) {
alert("User cancelled the Facebook login or did not fully authorize.");
}
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3&appId=920929871279093";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-login-button" data-max-rows="3" data-size="medium" data-show-faces="true" data-auto-logout-link="true"></div>
My problem is that when I run this piece of code I get following error but login button appears and work fine.
As I search for this issue people are saying I change
//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3&appId=920929871279093";
To
//connect.facebook.net/en_US/sdk.js#xfbml;
or
//connect.facebook.net/en_US/sdk.all;
I do not understand how this really work. And appreciate if anyone say where I am calling init.FB twice and how to fix it.
I think you need to put version number in init function:
The following is the example from parse.com https://www.parse.com/docs/js/guide#users-setup
<script>
// Initialize Parse
Parse.initialize("$PARSE_APPLICATION_ID", "$PARSE_JAVASCRIPT_KEY");
window.fbAsyncInit = function() {
Parse.FacebookUtils.init({ // this line replaces FB.init({
appId : '{facebook-app-id}', // Facebook App ID
status : true, // check Facebook Login status
cookie : true, // enable cookies to allow Parse to access the session
xfbml : true, // initialize Facebook social plugins on the page
version : 'v2.3' // point to the latest Facebook Graph API version
});
// Run code after the Facebook SDK is loaded.
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

Clicking the like in the website should like in Facebook

from here i got that code and i placed in my website localhost but cannot able to see any change .Can anyone help me this
i got the code from here http://developers.facebook.com/docs/reference/plugins/like/
My code is like this
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://www.facebook.com/anicrave.shows" data-send="true" data-width="450" data-show-faces="true"></div>
Please check this link and add the references to your page.
http://developers.facebook.com/docs/reference/javascript/
You're missing an essential part for FB-SDK in order to display the expected results.
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>

Categories

Resources