Facebook login not responding to FB.login response

I am working on an Android Android phone with facebook integration. The FB.login function (function (response) has a response handler that is called when the user presses the fb button, but does not receive a function response or warning ("test") each time. It gets into this script only when I hit about 5 or 6 times. Wat, I need to get the access token the first time I logged in to facebook. I looked through a lot of links regarding this, but cannot find the exact solution for this ...

FB login callback function not responding if user has already registered with facebook

Even this question seems the same, but I cannot understand its solution.

this is the code that works:

<div id="data">Hello Facebooktesters, loading ...</div> <button onclick="login()">Login</button> <button onclick="me()">Me</button> <button onclick="logout()">Logout</button> <button onclick="Post()">facebookWallPost</button> <script type="text/javascript"> document.addEventListener('deviceready', function() { try { alert('Device is ready! Make sure you set your app_id below this alert.'); FB.init({ appId : "xxxxxxxxxxxxxxx", nativeInterface : CDV.FB, useCachedDialogs : false }); document.getElementById('data').innerHTML = "FB init executed"; } catch (e) { alert(e); } }, false); function me() { FB.api('/me/friends', { fields : 'id, name, picture' }, function(response) { if (response.error) { alert(JSON.stringify(response.error)); } else { var data = document.getElementById('data'); fdata = response.data; console.log("fdata: " + fdata); response.data.forEach(function(item) { var d = document.createElement('div'); d.innerHTML = "<img src="+item.picture+"/>" + item.name; data.appendChild(d); }); } var friends = response.data; console.log(friends.length); for ( var k = 0; k < friends.length && k < 200; k++) { var friend = friends[k]; var index = 1; friendIDs[k] = friend.id; //friendsInfo[k] = friend; } console.log("friendId's: " + friendIDs); }); } function login() { FB.login(function(response) { alert('test'); if (response.authResponse) { alert('logged in'); var access_token = FB.getAuthResponse()['accessToken']; alert(access_token); window.location = "test.html" } else { alert('not logged in'); } }, { scope : "email" }); } function logout() { alert('test'); FB.logout(function(response) { alert('logged out'); //window.location.reload(); }); } function Post(ele) { var domain = 'http://192.168.0.46:8082/'; console.log('Debug 1'); var params = { method: 'feed', name: 'test - test', link: domain+'test/test/showproddetails.action?product.productId=1', picture: 'http://www.careersolutions.com/test.png', caption: 'test', description: 'test' }; console.log(params); FB.ui(params, function(obj) { console.log(obj);}); } </script> 

Thanks Raj

+4
source share
2 answers

This line is missing a semicolon:

window.location = "test.html"

0
source

This question was posted some time ago, but I would like to point out something. The FB.login function opens a pop-up dialog box asking if you want to enter the application using Facebook. It is generally recommended that you run it after clicking the button, since most browsers block pop-up dialogs when the page loads. If the user has previously allowed your application, the pop-up dialog box is redirected back to your application and closes the dialog box (provided that your application is a website).

If you intended to do this to check if the user is registered in your application when the page loads, it is recommended to use the FB.getLoginStatus method FB.getLoginStatus

 function checkLoginState() { FB.getLoginStatus(function(response) { // Check response.status to see if user is logged in alert(response.status); }); } 

Refer to this extensive facebook documentation

0
source

All Articles