Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook PHP SDK $uid = $facebook->getUser() always returns 0
    primarykey
    data
    text
    <p>I am trying to integrate our DB with the facebook API , really new on this so I would appreciate some help.</p> <p>I am always getting 0 </p> <p>Using </p> <pre><code>$uid = $facebook-&gt;getUser() </code></pre> <p>I had a look to similar issues but didn't find a related solution.</p> <p>PHP</p> <pre><code>if($_REQUEST['action']=="signup" &amp;&amp; $_REQUEST['auth']=="facebook" &amp;&amp; !empty ($_REQUEST['auth']) &amp;&amp; !empty ($_REQUEST['action']) ) { require_once('libs/facebook/src/facebook.php'); $config = array(); $config['appId'] = 'xxxx'; $config['secret'] = 'xxxxxx'; $facebook = new Facebook($config); $uid = $facebook-&gt;getUser(); echo $uid; } //else {} normal sign up here with all the error checking </code></pre> <p>HTML</p> <pre><code>&lt;div class="fb-login-class"&gt; &lt;div class="fb-login-button" autologoutlink="true" scope="publish_stream" perms="email,user_birthday" data-show-faces="false" data-width="200" data-max-rows="1"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>JAVASCRIPT / JQUERY</p> <pre><code>window.fbAsyncInit = function() { // init the FB JS SDK FB.init({ appId : 'XXXX, // App ID from the app dashboard channelUrl : '//WWW.XXXX.com', // Channel file for x-domain comms 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 // will be handled. FB.Event.subscribe('auth.authResponseChange', function(response) { // Here we specify what we do with the response anytime this event occurs. if (response.status === 'connected') { loginfunction(); } else if (response.status === 'not_authorized') { FB.login(function(response) {},{scope: 'email'}); } else { FB.login(function(response) {},{scope: 'email'}); } }); }; (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_GB/all.js#xfbml=1&amp;appId=XXXXX"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); function loginfunction() { console.log('Welcome! Fetching your information.... '); FB.api('/me', function (response) { console.log(response); /*I can see all the data here and the button also changes so I know that I am logged in */ var data = 'action=signup&amp;username=' + response.username + '&amp;firstname=' + response.first_name + '&amp;gender=' + response.gender + '&amp;lastname=' + response.last_name + '&amp;email=' + response.email + '&amp;dob=' + "xxxx" + '&amp;auth=facebook'; /*What's the point in passing all these parameters through ? only need to pass &amp;auth=facebook and action=signup I guess the rest can be manipulated anyway so what's the point need to get them from PHP SDK (server side ajax call) */ $.ajax({ type: "POST", url: "actions/do_signup.php", data: data, beforeSend: function (html) {}, success: function (html) { if (html == "success") { window.location.replace("index.php"); } else {} } }); }, { scope: 'email' }); } </code></pre> <p>thanks</p> <p>EDIT tried that only with PHP still failed </p> <pre><code>require('facebook.php'); $facebook = new Facebook( array ( 'appId' =&gt; 'xxx', 'secret' =&gt; 'xxxx', 'cookie' =&gt; true ) ); if ($_REQUEST['act']=="fb") { //$next_url = $facebook-&gt;getLoginStatusUrl($params); if ($facebook-&gt;getUser()) { $userProfile = $facebook-&gt;api('/me'); $uid = $facebook-&gt;getUser(); // do logic echo $uid ; echo "ok"; } else { echo "problem"; $loginUrl = $facebook-&gt;getLoginUrl($params = array('scope' =&gt; user_birthday,read_stream,'redirect_uri' =&gt; 'http://xxxx/index.php?act=success')); header('Location:' . $loginUrl); } } else if ($_REQUEST['act']=="success") { try{ $_SESSION['fbAT'] = $facebook-&gt;getAccessToken(); }catch(Exception $e){ trigger_error("FB AccessToken: " . $e-&gt;getMessage()); } $facebook-&gt;setAccessToken($_SESSION['fbAT']); if ($facebook-&gt;getUser()) { $uid = $facebook-&gt;getUser(); $userProfile = $facebook-&gt;api('/me'); // do logic echo $uid ; echo $userProfile; echo "ok"; } else { $uid = $facebook-&gt;getUser(); echo $uid ; echo "still problem"; } </code></pre> <p>Some steps that I have tried:</p> <ul> <li>Sandbox Mode is disabled and I have confirmed the app id and secret as well... </li> <li>Tried adding header : header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');</li> <li>Added cookie' => true</li> <li>Try calling it from a static page not through ajax still 0 </li> <li>Only website is used under facebook basic tab </li> <li>Under advanced app type is set to web</li> <li>Under permissions default activity is public</li> <li>Made sure that fb_ca_chain_bundle.crt is in the same dir that facebook.php also tried to use a different dir (the same with my php file) <ul> <li>Trying only PHP and getLoginUrl with additional scope to get access.</li> <li>Trying getting and setting an access token</li> </ul></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload