FB.api('/me/likes/124745260879931', onMyLikesResponse); not working on IE 9 - facebook

any reason why the below code would not work in IE9 yet work in every other browser i try?:
FB.init({appId: '######', status: true, cookie: true, xfbml: true});
FB.api('/me/likes/######', onMyLikesResponse);
function onMyLikesResponse(response)
{
console.log("length" + response.data.length);
console.log(response);
if(response.data.length==1){
$('#like').show();
}
}

FB.login(function(response) {
if (response.status == 'connected') {
var page_id = "40796308305";
FB.api('/me/likes/'+page_id, function(response) {
if (response.data[0]) {
$('#like').show();
}
});
} else {
// user is not logged in
}
});
I think length will not work on json response. Make sure developer tools are open in IE9, cause you are using console.log.

Related

FB share after login

When popup for access closed, browser blocking new popup for share. It is possible to give the right and open the window share? (without blocked popup)
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/en_US/sdk/debug.js', function(){
FB.init({
appId : '856902511027949',
status : true,
cookie : true,
xfbml : true,
oauth : true,
version : 'v2.2'
});
});
function shareViaFbApp() {
FB.ui({
method: 'share',
href: 'https://developers.facebook.com/docs/',
display: 'popup'
}, function(response){
console.log(response);
});
}
$(".init").on('click', function(event) {
event.preventDefault();
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
shareViaFbApp();
} else {
FB.login(function(response) {
console.log(response);
if (response.authResponse) {
shareViaFbApp();
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'publish_actions'});
}
});
});
I see only one way to get around this problem, create a block like fb popup share after FB.login(), and make share via FB.api().
You should not use FB.login in the asynchronous callback of FB.getLoginStatus. I know that it´s in an example in the Facebook docs, but it´s wrong and modern browsers block it. Use FB.getLoginStatus on page load (to refresh a user session and to check if a user is logged in) and FB.login directly on user interaction (mouse click).
You should not use FB.ui automatically either, only on direct user interaction like FB.login.
Btw, you don´t need to authorize a user for FB.ui, it will work without FB.login too.
So, i find workaround, if you need show share dialog after providing access to your fb app, use display: 'iframe' for this.
function shareViaFbApp(afterAccess) {
var display;
if (afterAccess) {
display = 'iframe';
} else {
display = 'popup';
}
FB.ui({
method: 'share',
href: 'https://developers.facebook.com/docs/',
display: display
}, function(response){
console.log(response);
});
}
$(".init").on('click', function(event) {
event.preventDefault();
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
shareViaFbApp();
} else {
FB.login(function(response) {
console.log(response);
if (response.authResponse) {
shareViaFbApp(true);
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'publish_actions'});
}
});
});

Cordova Facebook Connect - can't get userID

I added to phonegap app Facebook Connect,
It works fine and generates Access Token, But when I'm trying to get the userID the value is
"Undenified"
my function:
FB.init({
appId: "************",
nativeInterface:CDV.FB,
xfbml: true,
useCachedDialogs: false,
status: true,
cookie: true,
oauth: true
});
//alert("Init Done");
FB.getLoginStatus(function (response) {
if (response.authResponse) {
if (response.status == 'connected') {
Token = response.authResponse.accessToken;// This one is Good!
userid = response.authResponse.userID;// This one is Bad
}
I use the following and it works fine:
FB.api('/me', {}, function (response) {
fbuserid = response.userid;
});
This gives you the user data. You can also pass the scope just to get what you want like email, userid, etc...
Iterate through the keys to see what is stored
for (var key in response.authResponse) {
console.log(key);
console.log(response.authResponse[key]);
}

Facebook API: send message to friends works for only test/admin users

I'm working on a website, as part of that we are allowing users to invite their friends. Using following code
// assume we are already logged in
FB.init({appId: 'xxxxxxxx49030', xfbml: true, cookie: true});
function sendInvites(fb_ids) {
var link_url = "<?php echo base_url()?>invited/?code=100627510332492694";
FB.ui({
method: "send",
to: fb_ids,
name: "Join example.com",
description: "hello",
picture: "http://www.example.com/images/logo-orange.png",
link: link_url
}, function(response) {
alert(response)
if (!response){
return;
}
$.post("/invite/new/", {
fb_ids: fb_ids
}, function(data) {
if (data.status == "success") {
alert(data.status);
} else {
alert(data.message);
}
}, "json");
});
}
Don't understand what's missing.
Fbids should be an array and i missed it. It's working now.

FB.getLoginStatus returns a session even after the user has logged out of Facebook

This is driving me crazy. A user logs into my Facebook app, does some stuff. Then goes to Facebook and logs out. I've got a little timer that calls FB.getLoginStatus() every once in a while to see if the user is still logged in. But whenever FB.getLoginStatus() gets called it returns a response with a session object. WTF? Shouldn't it return undefined/unknown?
I'm using the absolute most basic call to Facebook evar:
FB.init({
appId: 'MY APP ID',
cookies: false,
status: true,
xfbml: false
});
FB.getLoginStatus(function (response) {
if (response.session) {
console.info("Session exists");
} else {
console.info("Session empty");
}
});
setInterval(function () {
FB.getLoginStatus(function (response) {
if (response.session) {
console.info("Session exists");
} else {
console.info("Session empty");
}
});
}, 10000);
I checked and double checked the permissions that are being requested with the allow. I am only requesting email and sms. So.... any advice?
don't do it in the hard way. This situation has a simple solution, just add a "true" statement as a second parameter from the getLoginStatus method:
FB.getLoginStatus(function (response) {
if (response === undefined || response.status === 'connected') {
// Do something after logout
}
}, true);
Just be careful and aware that every call to this function will make your App to go to Facebook's servers and can give you a considerable amount of network load depending on your implementation. Hope this helps!
I had the same problem using your code.
The only way I got round it so far is to initialise the sdk each time login status is queried:
setInterval(function () {
FB.init({
appId : 'xxxx', // App ID
channelUrl : 'xxxx', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
FB.getLoginStatus(function (response) {
if (response.authResponse) {
console.info("Session exists");
} else {
console.info("Session empty");
}
});
}, 10000);
In this way I always get the correct session status. If there's a more efficient way to do this please let me know!
Try initializating FB with
status: false
So it will work as you expect. It worked for me
Are you sure the session always gets destroyed when the user logs out? Maybe it's just a var inside the session that changes if the users logs in or out....?

Facebook authorization in C#

How do I implement a Facebook authorization? I have no idea where to start. I have seen numerous examples in PHP but none in C#.
Start here: http://developers.facebook.com
If you can use the Facebook javascript sdk (Much easier IMO, and you have asp.net as a tag so i am making assumptions) you could try something like this:
//Facebook iFrame include
window.fbAsyncInit = function () {
FB.init({ appId: YourID, status: true, cookie: true, xfbml: true });
FB.Canvas.setAutoResize();
authorize();
}
/*
* Facebook Authorization
*/
function authorize (){
FB.getLoginStatus(function (response) {
if (response.session) {
// logged in and connected user, carry on
} else {
// no user session available, Lets ask for perms
FB.ui(
{
method: 'permissions.request',
perms: your permissions
},
function (response) {
if (response && response.session != null) {
//User accepted permissions
} else {
//User did not accept permissions
}
});
}
});
}