Facebook uid retrieve different number - javascript

Im trying to get the uid but is retrieving different number.
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
alert ("Your UID is " + response.authResponse.userID);
}
});
I use Graph API tool and put me?fields=id .
The result is 10000607333xxxx (CORRECT UID)
But when I use de js code at the bottom retrieve different uid 1493309240881506
I try with php $facebook->getUser() and is the same different number
What i am doing wrong ?
UPDATE
Someone tell me that is the scopeduserid but i need the global uid because with this number i have to verify if is a FAN of my page
SELECT uid FROM page_fan WHERE page_id = '23223322332xxx' and uid="+user_id;
This fql select only gave me results with the global uid.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Documento sin título</title>
<script src="http://connect.facebook.net/en_US/all.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script>
FB.init(
{
appId : '52150228463xxxx',
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') {
alert ("Your UID is " + response.authResponse.userID);
}
});
</script>
</body>
</html>

Related

How to log out of my facebook app but not facebook using javascript sdk?

I have searched for this and the answers were VERY unclear and outdated.
So - I am using Facebook Javascript SDK to allow people to log in and out of my site. When they log out, I want them to be able to stay logged in to Facebook.
I am using standard code:
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
testAPI();
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : '#######',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.2' // use version 2.2
});
// Now that we've initialized the JavaScript SDK, we call
// FB.getLoginStatus(). This function gets the state of the
// person visiting this page and can return one of three states to
// the callback you provide. They can be:
//
// 1. Logged into your app ('connected')
// 2. Logged into Facebook, but not your app ('not_authorized')
// 3. Not logged into Facebook and can't tell if they are logged into
// your app or not.
//
// These three cases are handled in the callback function.
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(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'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', {fields: 'name,email'}, function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
}
</script>
<!--
Below we include the Login Button social plugin. This button uses
the JavaScript SDK to present a graphical Login button that triggers
the FB.login() function when clicked.
-->
<fb:login-button data-auto-logout-link="true" scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
<div id="status">
</div>
</body>
</html>
PERFECT! I figured it out on my own. The answer is two part. You need to revoke access. You do this like this in your javascript:
function logoutFacebook()
{
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/'+uid+'/permissions', 'delete', function(response){});
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
}
Then, you add a button to fire off that function:
<button id="logout" onclick="logoutFacebook()">Logout</button>

Integrating Facebook SDK in Windows 8 JS application

I'm trying to develop a Windows 8 app and I want to integrate Facebook in it.
I know this can be done without their SDK, but I've seen it can also be done with it and I'd love to go for the SDK.
I have the all.js file downloaded and referenced.
I included the initialization code in default.html:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
// init the FB JS SDK
FB.init({
appId: '*******', // App ID from the app dashboard
status: true, // Check Facebook Login status
xfbml: true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
};
</script>
I'm trying to login using FB.login() when a button is pressed, but it's not working because
FB.getLoginStatus(function (response) {
console.log("entered")
if (response.status === 'connected') {
console.log("connected");
} else {
console.log("connecting");
FB.login(function (response) {
if (response.authResponse) {
console.log("connected");
} else {
console.log("canceled");
}
});
}
});
However, nothing happens when I click the button I attached this function to.
What can it be?
Any help is appreciated,
thanks!
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
alert("hh");
// Logged into your app and Facebook.
testAPI();
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : '197393374008468',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.7' // use version 2.2
});
// Now that we've initialized the SDK, we call
// FB.getLoginStatus(). This function gets the state of the
// person visiting this page and can return one of three states to
// the callback you provide. They can be:
//
// 1. Logged into your app ('connected')
// 2. Logged into Facebook, but not your app ('not_authorized')
// 3. Not logged into Facebook and can't tell if they are logged into
// your app or not.
//
// These three cases are handled in the callback function.
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(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/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
}
</script>
<!--
Below we include the Login Button social plugin. This button uses
the SDK to present a graphical Login button that triggers
the FB.login() function when clicked.
-->
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
<div id="status">
</div>
</body>
</html>

fbgetloginstatus: FB is not defined

I am getting the common JS error "Uncaught Reference Error: FB is not defined "
There are a lot of questions on the same issue and I have tried each solution available on
stackoverflow but to no avail. Apparently, people seem to get this issue sometimes, I am getting it all the time. Can anyone spot an error ? I am not using a chnnel url file for the time being
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function()
{
// init the FB JS SDK
FB.init=({
appId : 'xxxxxxxxxxx', // App ID from the App Dashboard
//channelUrl : 'www.something.in/channel.html', // Channel File for x-domain communication
status : false, // 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
} ;
</script>
<script type="text/javascript">
// Load the SDK's source Asynchronously
// Note that the debug version is being actively developed and might
// contain some type checks that are overly strict.
// Please report such bugs using the bugs tool.
(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 = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
alert(uid) ;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
alert("not authorised");
} else {
// the user isn't logged in to Facebook.
alert("NOTHING") ;
}
});
</script>
</body>
</html>
Can you get the basic example to work?
https://developers.facebook.com/docs/facebook-login/getting-started-web/
(the full text under section 3)
I could get the basic simple example to load BUT when I included my own code base FB was never defined.
It turned out to be the fact that I had prototyped "Object" to have a method called 'copyProperties'.
I changed that method to 'copyProps' and it all works now. So, if Facebook is prototyping Object for their own purposes then I'd guess there are some other potential collisions out there too.
Sure, this must be one reason everyone says not to prototype Object, but so convenient! Obviously, it's not enumerable, so don't yell at me too hard.
I had the same problem and I tried everything. I only solved it by requesting the Facebook script by jQuery and then initializing it:
$(document).ready(function()
{
$.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1", function () {
FB.init({ appId: 'xxxxxxxx', status: false, cookie: true, xfbml: true });
});
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
alert(uid) ;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
alert("not authorised");
} else {
// the user isn't logged in to Facebook.
alert("NOTHING") ;
}
});
Your code has a small mistake in FB.init=({.
You have to remove equal sign after FB.init and your code look like:
FB.init({
appId : 'xxxxxxxxxxx', // App ID from the App Dashboard
//channelUrl : 'www.something.in/channel.html', // Channel File for x-domain communication
status : false, // 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?
}) ;
One more mistake you have done . your div id is fb-root but at the time of initialize you declare facebook-jssdk id
just make sure both should be same

Facebook javascript integration with RoR does not work

Facebook login using the Javascript FB.getLoginStatus works in one case and does not work in anther.
This works:
//view
<script type="text/javascript">
function f1() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
FB.api('/me', function(response) {
alert(response.name + " " + response.id);
name1 = response.name;
uid1 = response.id;
});
// var uid = response.authResponse.userID;
// var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
}
</script>
<%= content_for :body_attributes, "onload='f1();'" %>
This does not work
// view
<script type="text/javascript">
function f1() {
// same definition as above
}
</script>
<script type="text/javascript"> {
f1()
}
</script>
I do not understand why the second code does not work. Thanks!
<script type="text/javascript">
{
f1()
}
</script>
Remove the braces and add a semicolon and you should be ok:
<script type="text/javascript">
f1();
</script>
This works:
//view
<script type="text/javascript">
function f1 {
FB.getLoginStatus(function(response) {
Hard to believe that this should work – because that’s not how you define a function in JavaScript. It’s missing the round brackets () after the function name.
[from comments] Doesn't FB.api have to be trigged by an event?
No, it doesn’t – it can be called from anywhere.
Just with methods that will (/might) create a popup window (FB.login, FB.ui) it is usually better to call them on user interaction such as a click, because otherwise modern browser’s popup blockers with default settings are likely to suppress the popup.

Facebook JavaScript SDK unexpected behaviour

Here's m code :
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '270423476xxxxx',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
<fb:registration
fields="name,birthday,gender,location,email"
redirect-uri="http://booktrolley.in/beta"
width="530">
Now if you go to my page on : http://www.booktrolley.in/beta/fbreg.php
There's this "Loading" animation that continues to be there, even after the page loads.Why is that so ?
Thanks
You are loading the plugin in a frame but your page's HTML structure is not correct, here's a better approach:
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<body>
<div id="fb-root" > </div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script src="jquery.js"></script>
<script>
$(document).ready(function() {
var wid=$(document).width()-20;
$("#fb").attr('width',wid);
});
FB.init({
appId : 'XXXXXXXXXXX',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
<fb:registration redirect-uri="http://booktrolley.in/"
fields='[
{"name":"name"},
{"name":"foo","description":"Type foo","type":"text"},
{"name":"bar","description":"Type bar","type":"text"},
{"name":"facebooker","description":"Pick Paul","type":"select","options":
{"coder":"Paul","pm":"Austin","partners":"Cat"}},
{"name":"check","description":"Check this","type":"checkbox"},
{"name":"date","description":"Dec 16 2010","type":"date"},
{"name":"city","description":"Calgary","type":"typeahead","categories":
["city"]}]'
onvalidate="validate"></fb:registration>
<script>
function validate(form) {
errors = {};
if (form.foo !== "foo") {
errors.foo = "You didn't type foo";
}
if (form.bar !== "bar") {
errors.bar = "You didn't type bar";
}
if (form.facebooker !== "coder") {
errors.facebooker = "Pick the geeky one";
}
if (!form.check) {
errors.check = "Check the little box";
}
if (form.date !== '12/16/2010') {
errors.date = "That isn't the launch date";
}
if (form.city.id !== '111983945494775') {
errors.city = "That isn't Calgary, Alberta";
}
return errors;
}
</script>
</body>
</html>
This is what the ancient Egyptians called "a bug"

Categories

Resources