粉丝页面标签iframe中的facebook getUser()仅在IE上显示内部服务器错误

时间:2014-03-19 13:16:03

标签: php facebook internet-explorer iframe facebook-page

我在facebook页面选项卡上有一个使用getUser的应用程序,这样我就可以获得它在Chrome和Firefox上运行的用户的脸书ID,但不会在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;
            }
}
?>

提供错误500的网址:

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.crt都在同一个文件夹中,文件夹

在html文件的顶部,在此代码的标题之后:

<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网站。

更新

如果我使用此网址https://MYWEBSITE.com/matchgame/register直接从我的网站进入应用程序,那么我回到Facebook的应用程序是有效的,它接缝有一些cookie被阻止,如果我从中输入应用程序Facebook的!!!

1 个答案:

答案 0 :(得分:1)

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

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代码。

相关问题