0

I have a problem with Facebook apps on Internet Explorer. On other browser it works normally, but on IE i get error:

Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /base_facebook.php on line 1340

I find the connection with this error. It's in my code in line

$userinfo = $facebook->api('/me');

Hire is my code:

<?php
session_start();
header('Content-Type: text/html; charset=UTF-8');
require 'facebook.php';

// APPS INICIALIZATION
$appid = '123APPID123';
$facebook = new Facebook(array(
  'appId'  => $appid,
  'secret' => '123SECRETID123',
  'cookie' => true,
));
// END - APPS INICIALIZATION

?>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<script src="https://connect.facebook.net/en_US/all.js"></script>
<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
              appId      : '123APPID123', // App ID
              status     : true, // check login status
              cookie     : true, // enable cookies to allow the server to access the session
              xfbml      : true  // parse XFBML
        });
    };

    (function(d){
        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.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));

</script>
<br>

<?php 

// RETRIVAL DATA AND OTHERS INFO
$userid = $facebook->getUser();
$userinfo = $facebook->api('/me');
// END - RETRIVAL DATA AND OTHERS INFO

// PUT DATA TO VARIABLE
$email = $userinfo['email'];
$first_name = $userinfo['first_name'];
$last_name = $userinfo['last_name'];

// DATA TESTER //
echo $email.'<br>';
echo $first_name.'<br>';
echo $last_name.'<br>';
?>

Do you have any idea?

kris_IV
  • 2,396
  • 21
  • 42
  • How do you login the user? I assume $userid is 0 in your code? – WizKid Jun 09 '14 at 17:57
  • This is apps on Facebook. First php script check: you like this page and you are login, and this is second script - only show discount and put user info to database. – kris_IV Jun 10 '14 at 07:22
  • You need an access token from the user to do requests as that user. And if you are using user_likes for like-gating that will not be approved by Facebook – WizKid Jun 10 '14 at 15:41
  • But I have this access_token from my users but not on Internet Explorer ;-) I made echo for this $access_token and on all browsers I see normal token key, but on IE i see may APP_ID|APP_SECRET instead of normal access token. And I think that this is key of this problem. This part with like-gating work OK on all browser (IE also). The problem is only to get user data. – kris_IV Jun 11 '14 at 05:46
  • If the app was created after 4/30/2014 Facebook will have to review your use of user_likes before you can ask users that don't have a role on the app. And they will not approve it if you use it for like-gating – WizKid Jun 11 '14 at 05:53
  • I found solution. It was problem with cookie on IE. When I add this line i get normal user ID and everything work OK. header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); – kris_IV Jun 11 '14 at 07:39

1 Answers1

0

For everybody who have the same problem with IE and facebook authorization. The problem is not connected with $facebook->api('/me'); or $facebook->getUser(); . You can check it by use :

print_r($facebook->getUser());

If you get 0 in answer it means that IE doesn't send all cookies to your PHP script. You should start your PHP code with this line after start php file:

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

Now IE send all cookies without any problems.

kris_IV
  • 2,396
  • 21
  • 42