简体   繁体   English

Facebook 应用程序在 IE 中不起作用(重定向到主机 Canvas 回调 URL)

[英]Facebook application doesn't work in IE(Redirecting to the host Canvas Callback URL)

I have a file named fbmain.php which do all facebook authentication parts.我有一个名为 fbmain.php 的文件,它执行所有 facebook 身份验证部分。 And I have a button in index.php file which passes data to a.php file我在 index.php 文件中有一个按钮,它将数据传递给 a.php 文件
This is just an example这只是一个例子

//fbmain.php : do all facebook authentication parts

//index.php
      <?php
           include_once "fbmain.php";
       ?>
<form enctype="multipart/form-data" action="http://myserver/a/a.php" method="POST">
     //Some codes 
     <input type="submit" value="Upload"/>
</form>

In a.php file I have to include fbmain.php again since here I do some api call.在 a.php 文件中,我必须再次包含 fbmain.php,因为我在这里做了一些 api 调用。

  //a.php
<?php    
    include_once "fbmain.php";

        //some codes            
            try{            
                $me = $facebook->api('/me?access_token='. $token); 
                print_r($me);               
            } catch(FacebookApiException $e){
                echo "Error:" .$e;
            }
?>

THis app works fine in firefox browser but doesnt work in IE(When the user click 'Upload button it redirect user to the host Canvas Callback URL').此应用程序在 firefox 浏览器中运行良好,但在 IE 中不起作用(当用户单击“上传按钮时,它将用户重定向到主机 Canvas 回调 URL”)。

I tried placing bellow codes at the top of in each and every file(fbmain.php, index.php, a.php).我尝试在每个文件的顶部放置以下代码(fbmain.php,index.php,a.php)。 But it still doesn't work?但是还是不行?

First I tried this首先我试过这个

header('P3P: CP=HONK');
ob_start();

Then I tried this然后我尝试了这个

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

But nothing works in IE.但是在 IE 中没有任何作用。
Can anyone please help me?谁能帮帮我吗?

//fbmain.php file //fbmain.php文件

<?php
    //header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
    header('P3P: CP="CAO PSA OUR"');
    ob_start();
    //facebook application
    //set facebook application id, secret key and api key here
    $fbconfig['appid' ] = "MY_APP_ID";      
    $fbconfig['api'   ] = "MY_API_KEY";
    $fbconfig['secret'] = "MY_APP_SECRET";

    //set application urls here
    $fbconfig['baseUrl']    =   "http://MYSERVER/uploader/index.php"; //http://thinkdiff.net/demo/newfbconnect1/iframe;
    $fbconfig['appBaseUrl'] =   "http://apps.facebook.com/approne"; //http://apps.facebook.com/thinkdiffdemo;

    $uid            =   null; //facebook user id

    try{
        include_once "facebook.php";
    }catch(Exception $o){
        echo '<pre>';
        print_r($o);
        echo '</pre>';
    }
    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true,
    ));

    //Facebook Authentication part
    $session = $facebook->getSession();

    $loginUrl = $facebook->getLoginUrl(
            array(
            'canvas'    => 1,
            'fbconnect' => 0,
            'req_perms' => 'email,publish_stream,status_update,user_photos'
            )
    );
    if (!$session) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
        exit;
    } 
    if ($session) {
        try {
            $uid      =   $facebook->getUser();
                //Has a loading problem
        } catch (FacebookApiException $e) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
            exit;
        }       
    }

    $signed_request = $_REQUEST['signed_request'];
    $secret = $fbconfig['secret'];
    $data = parse_signed_request($signed_request, $secret);
    $fan_page_id = $data['page']['id'];
    $admin_check = $data['page']['admin'];

        //Get fan page id
    function parse_signed_request($signed_request, $secret) {

        list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

        // decode the data
        $sig = base64_url_decode($encoded_sig);
        $data = json_decode(base64_url_decode($payload), true);

        if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
            error_log('Unknown algorithm. Expected HMAC-SHA256');
            return null;
        }

        // check sig
        $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
        if ($sig !== $expected_sig) {
            error_log('Bad Signed JSON signature!');
            return null;
        }
        return $data;

    }

    function base64_url_decode($input) {
        return base64_decode(strtr($input, '-_', '+/'));
    }   

?>

I came across a similar issue with IE before where the user session was not persisting server side.在用户 session 没有持久化服务器端之前,我遇到了与 IE 类似的问题。 To get around it I added a hidden field to forms served to IE containing the signed_request .为了解决这个问题,我在 forms 中添加了一个隐藏字段,该字段提供给包含signed_request的 IE。

<input type='hidden' name='signed_request' value='VALID_SIGNED_REQUEST' />

But this solution should work with the code parameter or by passing the authorisation token and then using it to restore the users session server side.但是此解决方案应使用code参数或通过传递授权令牌然后使用它来恢复用户 session 服务器端。 You can also try maintaining your own session cookie.您也可以尝试维护自己的 session cookie。


I see you are using the pre v3 of the PHP SDK.我看到您使用的是 PHP SDK 的 pre v3。 So you should try adding the hidden field:所以你应该尝试添加隐藏字段:

<input type='hidden' name='session' value='<?php echo json_encode($session); ?>' />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM