facebook的getUser()在风扇页标签iframe显示内部服务器错误仅在IE上


facebook getUser() in fan page tab iframe shows internal server error only on IE

我在facebook页面标签上有一个应用程序,使用getUser,这样我就可以获得该用户的facebook id,它在Chrome和Firefox上都有效,但在IE上不行。我多次尝试清空缓存!这是我正在做的(这是codeigniter框架)

<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Register extends CI_Controller {
    function __construct() {
        parent::__construct();
        $this->load->library('facebook', $this->config->item('fb_config'));
        $this->load->library('Form_validation');
        $this->load->library('session');
        $this->load->model('users_model', 'users');
    }
public function index() {
   $user_id = $this->facebook->getUser();

            if ($user_id) {
                    // We have a user ID, so probably a logged in user.
                // If not, we'll get an exception, which we handle below.
                try {
                    $user_profile = $this->facebook->api('/me', 'GET');

                    $data['fb_id'] = $user_profile['id'];
                        $this->session->set_userdata('fb_id', $data['fb_id']);
                    $users = $this->users->get_by_fb_id_register($data['fb_id'], array('full_name', 'age', 'email', 'phone_number'));
                    // not first time
                    if ($users != 0 && $users->num_rows() < 1) {
                            $data['full_name'] = $user_profile['name'];
                        $birthDate = explode("/", $user_profile['birthday']);
                        $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y") - $birthDate[2]) - 1) : (date("Y") - $birthDate[2]));
                        $data['age'] = $age;
                        $data['email'] = $user_profile['email'];
                    } else {
                        $data = $users->row_array();
                    }
                } catch (FacebookApiException $e) {
                    // If the user is logged out, you can have a
                    // user ID even though the access token is invalid.
                    // In this case, we'll get an exception, so we'll
                    // just ask the user to login again here.
                    $login_url = $this->facebook->getLoginUrl(
                            array(
                                'scope' => 'email, user_birthday, publish_actions, publish_stream', //read_stream, friends_likes, user_likes
                           // 'redirect_uri' => $this->config->item('fan_page_app_link'), //the url to go to after a successful login
                    ));
                    echo '<script> window.top.location.href = "' . $login_url . '"; </script>';
                    exit;
                }
            } else {
                // No user, print a link for the user to login
                $login_url = $this->facebook->getLoginUrl(
                        array(
                            'scope' => 'email, user_birthday, publish_actions, publish_stream', //read_stream, friends_likes, user_likes
                        'redirect_uri' => $this->config->item('fan_page_app_link'), //the url to go to after a successful login
                ));
                echo '<script> window.top.location.href = "' . $login_url . '"; </script>';
                exit;
            }
}
?>

给出错误的url:

https://www.facebook.com/dialog/oauth?client_id=1397280120532513&redirect_uri=https%3A%2F%2FMYWEBSITE.com%2Fmatchgame%2Fregister&state=bc353f470176d5a62995722808e3f406&sdk=php-sdk-3.2.3&scope=email%2C+user_birthday%2C+publish_actions%2C+publish_stream

我不知道这是否与错误有关,但我做了以下操作:

我对facebook.php文件所做的唯一更改是将其重命名为facebook.php,并添加了这一行
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;

__construct,因为我得到了这个错误

Invalid or no certificate authority found, using bundled information

虽然所有三个文件facebook.php, base_facebook.php和fb_ca_chain_bundle. phplibraries文件夹

放在HTML文件的顶部,在header之后,这段代码:

<script type="text/javascript">
        function NotInFacebookFrame() {
            return top === self;
        }
        function ReferrerIsFacebookApp() {
            if (document.referrer) {
                return document.referrer.indexOf("apps.facebook.com") != -1;
            }
            return false;
        }
        if (NotInFacebookFrame() || ReferrerIsFacebookApp()) {
            top.location.replace("<?php echo $this->config->item('fan_page_app_link'); ?>");
        }
    </script>

这样,如果用户直接从网站访问应用程序,他将被重定向到facebook网站。

如果我使用这个url https://MYWEBSITE.com/matchgame/register直接从我的网站进入应用程序,那么我从facebook返回应用程序是有效的,它似乎有一些cookie被阻止,如果我从facebook进入应用程序!!

我终于找到了解决方案,显然我需要IE接受跨浏览器cookie是一个P3P策略头,因为这是一个PHP应用程序,所以我所做的是在任何页面输出之前的以下代码位:

header('p3p: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"');

或者

<meta http-equiv="P3P" content='CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"' />

如果你使用的是PHP以外的任何东西,或者如果你更喜欢元标记而不是PHP代码,