FB.login Error in Internet Explorer - facebook

I am using connect-js (FB.login) to login users to share my page, in standard way. In all normal browsers (chrome, firefox, opera) it pops up a window with permissions request (everything is fine). But in Internet Explorer (7 and 8, didn't test in 6) it pops up window that says: "An error occurred with [myapp]. Please try again later."
This is my code:
<div id="fb-root"></div>
<script language="javascript">
var nombre = "";
var pic_big = "";
FB.init({
appId : '161599150607341', // App ID
channelUrl : '//emocionesverde.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
});
function conectarse() {
FB.login(handleSessionResponse, {
scope: 'publish_stream, user_about_me'
});
}
function handleSessionResponse(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
//console.log(response.name);
window.nombre = response.name;
getUserPic(response.id);
});
}
}
function getUserPic(uid) {
FB.api('/me?fields=picture&type=large', function(response) {
//console.log(response.picture);
window.pic_big = response.picture;
publicar();
});
}
function publicar() {
FB.ui({
method: 'stream.publish',
message: '',
attachment: {
name: 'Emoción es Verde',
caption: window.nombre + ' midió el impacto de sus acciones verdes. Te invitamos a conocer acciones para mantener el planeta verde con Emoción es Verde',
media: [{
type: 'flash',
swfsrc: 'http://mainteractivetools.com/erik/mifb/emocionesverde/Prueba.swf?pic=' + window.pic_big + '&nombre=' + window.nombre,
imgsrc: 'http://mainteractivetools.com/erik/mifb/emocionesverde/telefonica1.jpg',
expanded_width: '450',
expanded_height: '258'
}],
href: 'http://www.emocionesverde.com'
},
action_links: [{
text: 'Emoción es Verde',
href: 'http://www.emocionesverde.com'
}],
user_message_prompt: 'Escribe un comentario'
}, function (response) {});
}
$('#swfmapsdiv').css('visibility', 'hidden');
</script>

Have you tried adding p3p headers? It's an IE thing and clears up a lot of problems. However cryptic the codes are. What Facebook is essentially trying to do is share cookies across domains, which is a security flag. You need to say it's ok.

The issue could be in channelUrl, try to have the whole path there i.e http://emocionesverde.com/channel.html
Also login into facebook as app developer - the error message will be more detailed

Related

Facebook Feed Dialog does not open

I am building a custom multi friend selector in order to send posts to friend's walls on Facebook based on this tutorial
https://developers.facebook.com/docs/guides/games/custom-muti-friend-selector/
I have been able to load my list of friends and create a CSV list of people I want to post to but the last step of opening the feed dialog is failing and I don't understand why. The dialog does not open.
this is my sendRequest function
var sendUIDs = '';
$('.cbFriendId').each(function(index){
if($(this).prop('checked') == true){
var addId = $(this).attr('value');
sendUIDs += addId + ',';
}
});
console.log(sendUIDs);
openSendDialog(sendUIDs);
}
function openSendDialog(sendUIDs){
console.log('open send dialog');
FB.ui({
method: 'feed',
to: sendUIDs,
link: 'http://www.mydomain.com',
display: 'iframe',
message: 'Hello from My Domain',
name: 'Click to view my app',
caption: 'Hello my app'
},
function (response) {
if (response) {
alert('Post was published.');
console.log('Post was published.');
} else {
alert('Post was not published.');
console.log('Post was not published.');
}
}
);
}
The last console log entry is 'open send dialog'. I get no errors in IE9 dev tools but I do get an 'Unsafe Javascript attempt to access frame ...' error in chrome.
just for sanity sake here is my graph init
window.fbAsyncInit = function () {
FB.init({
appId: '462750593765445', // App ID
channelUrl: '//www.mydomain.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
frictionlessRequests: false
});
};
Also I should mention that the app is in sandbox mode.
Thanks for the help
What you're trying to do is called Send Dialog, So you need to change your method from feed to send and it should work.
Check out their docs for more information: https://developers.facebook.com/docs/reference/dialogs/send/

API Error Description: Session key invalid or no longer valid (error 102)

I cant figure out why facebook publish is not working on this site
I get
API Error Code: 102
API Error Description: Session key invalid or no longer valid
Error Message: Iframe dialogs must be called with a session key
While calling the stream.publish method as iframe
<script type="text/javascript">
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/fr_FR/all.js';
document.getElementById('fb-root').appendChild(e);
}());
window.fbAsyncInit = function()
{
FB.init({ appId: '303380259758621',
status: true,
channelUrl: 'http://www.crabegame.com/channel.php',
cookie: true,
xfbml: true,
oauth: true});
}
function PublishStream(score)
{
FB.ui(
{
method: 'stream.publish',
display : 'iframe',
message : '',
attachment:
{
name: 'CrabeGame',
caption: 'Essaye de battre mon score sur le Crabe Game !',
description: "J'ai réalisé un score de " + score + "points au Crabe Game !",
href: 'http://www.crabegame.com',
media:
[
{
type: 'image',
src: 'http://crabegame.com/media/crabe_fb.png',
href: 'http://www.crabegame.com'
}
]
},
action_links:
[
{
text: 'Play Crabe Game',
href: 'http://www.crabe-game.com'
}
],
user_message_prompt: 'Publier sur votre mur'
},
function (response)
{
if (response && response.post_id)
{
}
}
);
}
</script>
This means that you have no current user. Try this in order to call PublishStream:
FB.login(function(response) {
if (response.authResponse) {
PublishStream();
} else {
console.log('Not logged in');
}
});
you don´t need a logged in user, just remove display: "iframe", worked for me. it will still show in an iframe, but without error. don´t ask me why, with 1:1 the same app settings it works WITH the display value in another app of mine...at least that worked for me with the apprequest dialog, might be the same here.
and i would use "feed" instead of "stream.publish".
see here: https://developers.facebook.com/docs/reference/dialogs/feed/
also: Using Like Button and FB.ui (apprequests) On the Same Page Conflicts

FB.login() causes Error 191 in any IE (Internet Exploder)

I have searched this problem for long now but all answers have not worked so far.
The code that calls for login:
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
document.getElementById("nimi").value = response.name;
document.getElementById("email").value = response.email;
FB.ui(
{
method: 'stream.publish',
attachment: {
name: 'Jõulupidu Maikrahv restoranis!',
caption: 'Broneeri firma jõulupidu hubases Maikrahv restoranis! Kingime Uusaasta pidulaua 10- le ja romantilise õhtusöögi kahele! ',
media: [
{
"type": "image",
"src": "http://ssl.advert.ee/maikrahv-joulupidu/maikrahv.jpg",
"href": https+"://ssl.advert.ee/maikrahv-joulupidu/"
}]
},
href: https+'://ssl.advert.ee/maikrahv-joulupidu/',
action_links: [
{ text: 'Maikrahv', href: https+"://ssl.advert.ee/maikrahv-joulupidu/" }
]
},
function(response) {
if (response && response.post_id) {
var ajaxresp = jagame_fbajax();
} else {
fb_alert("Teade!", "Postitust ei jagatud ja ei osale loosimises.");
}
}
);
});
} else {
fb_alert("Viga!", "Kuna õiguseid ei jagatud, ei saanud Sind osalemises kahjuks kirja panna")
}
}, {scope: 'email'});
}
Only IE gives this error
An error occurred with Jõulupidu Maikrahvis. Please try again later.
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: Invalid redirect_uri: Antud URL ei ole rakenduse konfiguratsiooni poolt lubatud.
Application settings:
App Domain: advert.ee ssl.advert.ee
Website:
Siute URL: http://ssl.advert.ee/maikrahv-joulupidu/
App on Facebook:
Canvas URL: http://ssl.advert.ee/maikrahv-joulupidu/
Secure Cavas URL: https://ssl.advert.ee/maikrahv-joulupidu/
Canvas Page: http://apps.facebook.com/maikrahv-joulupidu
Page Tab:
Page Tab Name: Jõulupidu Maikrahvis!
Page Tab URL: http://ssl.advert.ee/maikrahv-joulupidu/
Secure Page Tab URL: https://ssl.advert.ee/maikrahv-joulupidu/
Reported bug also:
https://developers.facebook.com/bugs/258868920826496
Please help. App must go live tomorrow :(
remove the channelUrl parameter from the fb init. IE reads the javascript incorrectly and puts the channel URL in the redirect_uri query var and it breaks the whole process.
Jacob rights.
I put this code:
if ( $.browser.msie ) {
FB.init({
appId : 'APP_ID',
status : true,
cookie : true,
oauth : true,
xfbml : true
});
} else {
FB.init({
appId : APP_ID,
channelUrl : '//example.com/channel.php', // Channel File
status : true,
cookie : true,
oauth : true,
xfbml : true
});
}
and solved the problem.

Extracting user id from Facebook Javascript SDK session object

I am using Facebook's Javascript SDK "FB.ui" to pull up an OAuth dialog. Once you click allow, I need to capture the session object, extract the user id and use it further in my script. For some reason I cannot get this working properly, I keep getting undefined, even though the session does exist.
<script src="http://connect.facebook.net/en_US/all.js"></script>
<div id="fb-root"></div>
<script type="text/javascript">
FB.init({
appId : '***************',
status : true,
cookie : true,
xfbml : true
});
FB.getLoginStatus(function(response) {
if (response.session) {
//do something
} else {
FB.ui({
method: 'oauth',
display: 'page',
scope: 'email',
perms: 'email'
},
function(response) {
alert(response.session.uid); //returns underfined
});
}
});
</script>
To get the userID:
FB.getLoginStatus(function(response) {
alert(response.authResponse.userID);
});
When you login from login button of facebook then it stores cookies in your system that contains your access token that is also unique. That cookies contains your facebook id also.
Check your response. I bet it says something like "display" must be one of "popup", "iframe" or "hidden". Apparently the oauth dialog cannot be called with the default "page" display. And display: 'iframe' requires that you include an access_token, which is why you're calling the oauth dialog in the first place >:l .
I don't think FB.ui can currently be used to get the oauth dialog, unless you want to use a popup, which most everyone has blocked nowadays.
So I got this to work as I would like. This may not be the best way, but after much digging around and frustration I hope this could help somebody with the same question get on the right track.
JS source:
FB.getLoginStatus(function(response) {
if (!response.session) {
//initiate FB OAuth js popup dialog
FB.ui({
method: 'oauth',
display: 'page',
scope: 'email',
perms: 'email'
},
function(response) {
if (response.session) { //if permission Allowed
var thesession = response.session;
var thesession = eval('(' + thesession + ')'); //decode json
//POSTing to local file get.user_graph.php, to fetch user info
$.ajax({
type: "POST",
url: "get.user_graph.php",
data: "client_id=<?php echo $appId; ?>&client_secret=<?php echo $secret; ?>&sessions="+thesession.session_key+"&type=client_cred&uid="+thesession.uid,
dataType: "text",
success: function(user_graph){
var user_graph1 = eval('('+user_graph+')');
alert(user_graph1.name); //users name
alert(user_graph1.id); //users id
alert(user_graph1.email); //users email
alert(user_graph1.link); //users profile link
}
});
} else {
//if permission Not Allowed
}
});
}
});
get.user_graph.php source:
//exchange our session for an access_token
define('POSTURL', 'https://graph.facebook.com/oauth/exchange_sessions');
define('POSTVARS', 'client_id='.$_POST['client_id'].'&client_secret='.$_POST['client_secret'].'&sessions='.$_POST['sessions'].'&type=client_cred');
$curl_token = curl_init(POSTURL);
curl_setopt($curl_token, CURLOPT_POST,1);
curl_setopt($curl_token, CURLOPT_POSTFIELDS,POSTVARS);
curl_setopt($curl_token, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl_token, CURLOPT_HEADER,0);
curl_setopt($curl_token, CURLOPT_RETURNTRANSFER,1);
$token = curl_exec($curl_token);
$token_decoded = json_decode($token,true);
//get the user graph (personal info)
$user_graph = file_get_contents("https://graph.facebook.com/".$_POST['uid']."?access_token=".$token_decoded[0]['access_token']);
echo $user_graph;

Facebook code to prompt for stream publish with in application

I have a bit confusion using facebook API. I am using a code that is working out side of facebook but not in facebook application canvas page.
I have bit idea but not sure. Can anybody let me know the reason behind this and the code that will run in facebook application.
What is difference you run code using application like
http://apps.facebook.com/exampleAPP/test.php
or normal url
http://www. example.com/example/test.php
http://www. example.com/example/ is the canvas URL
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '115454544334343454',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.ui(
{
method: 'stream.publish',
attachment: {
name: 'JSSDK',
caption: 'The Facebook JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
href: 'http://fbrell.com/'
},
action_links: [
{ text: 'fbrell', href: 'http://fbrell.com/' }
]
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
</script>
I'm fairly sure stream.publish is deprecated and unsupported. What you want instead is the Feed dialog.