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; </script>
Thanks Raj
source share