I am getting the following error when I press "Send Request" on my facebook multi friend selector dialog.
Unsafe JavaScript attempt to access frame with URL https://s-static.ak.fbcdn.net/connect/xd_proxy.php#cb=f13538d5d4&origin=http%3A%2F%2Fjoincrowdy.com%2Ff3b62245cc&relation=opener&transport=postmessage&frame=f145be71f&result=%7B%22request%22%3A%22271624056256532%22%2C%22to%22%3A[%22122614229%22]%2C%22updated_frictionless%22%3Afalse%7D from frame with URL http://MYAPP.com/rooms/1. Domains, protocols and ports must match.
I originally was developing on myapp.com:3000 but this error prompted me to try sending app request via production mode (port 80). That did not solve the issue.
NOTE: I added 127.0.0.1 myapp.com in my /etc/hosts Will that result in this error?
This is my code:
function initFb() {
window.fbAsyncInit = function() {
FB.init({
appId : user.fbAppId,
frictionlessRequests: true,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
});
// 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));
}
function attachInviteButton() {
$("#invite").click(sendRequestViaMultiFriendSelector);
}
function sendRequestViaMultiFriendSelector() {
FB.ui({
method: 'apprequests',
message: 'Invite your friends to play now.',
}, requestCallback);
}
function requestCallback() {
}
If you look at the JavaScript SDK documentation you'll see that when they call the FB.init they provide a channel url:
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
});
Which you have not.
In the same page, under the Channel File section there's an explanation of what it's good for and how to supply it.
It says clearly:
The channel file addresses some issues with cross domain communication
in certain browsers
This solution might fix that problem for you.
Related
I'm trying to use facebook sj sdk in a Chrome extension.
Im doing this on my extension init:
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId: 'APP_ID', // App ID from the App Dashboard
//channelUrl : '//www.example.com/', // Channel File for x-domain communication
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?
});
// Additional initialization code such as adding Event Listeners goes here
console.log(FB);
};
// Load the SDK's source Asynchronously
(function(d, debug) {
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 = "http://connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/false));
I'm getting this error:
Refused to load the script 'http://connect.facebook.net/en_US/all.js' because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:".
I have the permissiosn in manifest set to http://*/. How can I load the sdk from an extension?
This is because you are trying to load an external script from your Chrome extension. For security reasons to prevent cross-site-scripting you need a special permission in your manifest.json file.
"content_security_policy": "script-src 'self' https://connect.facebook.net; object-src 'self'"
Make sure you use https:// instead of http://.
I have implemented a Facebook based login.
The FB.login works perfectly, but the FB.logout doesn't. I have tried with different FB.init, deleting cookies, running the logout page several times in a row, but the only way to log my user out is in facebook itself.
The code I'm using for logout is:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId: '***************',
xfbml: true,
status: true,
cookie: true
});
FB.getLoginStatus();
FB.logout();
</script>
Any ideas?
Thank you
did you tried having some button onclick event is FB.logout();
function logout(){
FB.logout(function(response) {
// user is now logged out
});
}
<button onclick="logout()">LogOut</button>
Try This
Try to do this:
<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>
and then call the FB.logout(). FB must be initializad before.
From the documentation:
This code loads the SDK asynchronously so it does not block loading other elements of your page. This is particularly important to ensure fast page loads for users and SEO robots.
The URLs in the above code are protocol relative. This lets the browser to load the SDK over the same protocol (HTTP or HTTPS) as the containing page, which will prevent "Insecure Content" warnings.
The function assigned to window.fbAsyncInit is run as soon as the SDK is loaded. Any code that you want to run after the SDK is loaded should be placed within this function and after the call to FB.init. For example, this is where you would test the logged in status of the user or subscribe to any Facebook events in which your application is interested.
I need a little help with getting some JSON out of facebook, basically all I need to do is get the status text and post it to a website.
I'm using the method below, but the access_tokens with this method expires every hour.
$.getJSON('https://graph.facebook.com/SOME_ID?fields=statuses.limit(10).fields(message)&access_token=SOME_ACCESS_TOKEN', function(data) {});
Note that i got the URL above from facebook graph API explorer.
any other way to achieve what I am trying to do?
update:
I used FB.api, but i'm not sure if I've done it correctly as it is sending me this error
"An access token is required to request this resource."
window.fbAsyncInit = function() {
FB.init({
appId : 'My_app_id', // App ID
channelUrl : '//myHost.com/facebook/channel.php', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.api('USER_ID?fields=statuses.fields(message)', function(response) {
console.log(response);
});
// 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));
Note that i replaced (my_app_id, myHost.com and USER_ID) with the right values.
thanks in advance.
Assuming you have the Javascript SDK implemented i would suggest using the FB.api method.
https://developers.facebook.com/docs/reference/javascript/FB.api/
The user needs to be logged in to Facebook and allow your app before you can call the API, update your code to this:
window.fbAsyncInit = function() {
FB.init({
appId : 'My_app_id', // App ID
channelUrl : '//myHost.com/facebook/channel.php', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('USER_ID?fields=statuses.fields(message)', function(response) {
console.log(response);
});
}
});
};
More information on the getLoginStatus status: http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
You will also need to also need to ask the permission user_status see the doc for more details: https://developers.facebook.com/docs/authentication/permissions/
You should ask for permissions when calling FB.login:
FB.login(function(response) {
// handle the response
}, {scope: 'user_status'});
https://developers.facebook.com/docs/reference/javascript/FB.login/
I am trying to use javascript sdk for rendering a XFBML form on our site and i keep getting
Unable to load the registration form for . You may have previously blocked this app on Facebook. Go to your Facebook privacy settings to unblock this app. (Error: Invalid 'client_id'.)
my app is registered and with correct id.
the code looks like is:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '118446328234891', // App ID
channelUrl : '//www.sakshum.org/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>
<script src="https://connect.facebook.net/en_US/all.js#appId=118446328234891&xfbml=1"></script>
<fb:registration fields="name,birthday,gender,location,email" redirect-uri="http%3A%2F%2Fwww.sakshum.org%2FFbValidation" width="530">
</fb:registration>
just to add on if i use non xfbml version using just iframe then all works fine.
Looks like the issue was using encoded redirect_uri. changing it to normal url fixed the issue.
The redirect-uri must match with the setting "Site URL" in your Facebook app.
I am trying to add a facebook comments box using the social plugin to an application which will be running inside facebook as a facebook app.
When I view the app via its url it works fine however when I view the app in the dev facebook app the comments plugin does not load. Does anyone know if this is possible or if there are any additional settings required.
I have tried setting the data-href to the url of where the app is served from and the url of the facebook app neither seem to work
<div class="fb-comments" data-href="[MYDOMAIN]” data-num-posts="30" data-width="470"></div>
The code is just the standard snippet from fb js sdk
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '[MYAPPID], // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Canvas.setAutoGrow();
// 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));
Try providing a channel file and channelUrl.
From the Facebook JavaScript SDK documentation:
"...pages that include code to communicate across frames may cause Social Plugins to show up as blank without a channelUrl..."
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
});