php - Facebook登录阻止了一个框架问题

标签 php javascript jquery facebook facebook-login

注意 我阅读了有关此问题的所有相关问题,但找不到解决问题的方法。

Facebook Login API HTTPS Issue

Facebook: Unsafe JavaScript issue (document.domain values should be same)

我面临着被阻止的框架 facebook api 问题:

Blocked a frame with origin "https://www.facebook.com" from accessing a frame with origin "http://static.ak.facebook.com".  The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.

我遵循了 facebook api 教程并且正在使用此代码。

     window.fbAsyncInit = function() {
        FB.init({
          appId      : 'appID',
          status     : true,
          channelUrl : 'http://staging.mywebsite.com/login/channel',
          cookie     : true,
          xfbml      : true 
        });

        FB.login(function(response) {
            if (response.authResponse) {
                console.log('done');
            } else {
                console.log('problem');
            }
        });

        FB.Event.subscribe('auth.login', function(response) {
            console.log('test reponse');
            console.log(response);

        }); 
      };

      (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));

/login/channel 包含:

     $cache_expire = 60*60*24*365;
     header("Pragma: public");
     header("Cache-Control: max-age=".$cache_expire);
     header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT');
     echo '<script src="//connect.facebook.net/en_US/all.js"></script>';

fb 登录按钮:

     <fb:login-button width="200" max-rows="1" scope="email,user_birthday,user_interests,user_likes,user_location,user_hometown,user_mobile_phone,user_address"></fb:login-button>

我也试过了,但没有解决问题:

      channelUrl : '//staging.mywebsite.com/login/channel', //same issue

我错过了什么吗?或者我应该更改 Facebook 应用程序设置中的某些内容?

最佳答案

看来您可能需要修改下面的代码才能通过 https

(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 = "https://connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

此外,src="//domain.com 将继承协议(protocol)。您可以尝试:

echo '<script src="https://connect.facebook.net/en_US/all.js"></script>';

关于php - Facebook登录阻止了一个框架问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18735446/

相关文章:

php - 我将如何读取此数组 ("stdClass Object")

java - 返回java中的匿名对象

javascript - php 或 javascript session 规则弹出窗口

JavaScript:向上/向下滚动时突出显示一行

javascript - 用表单替换链接以将变量传递给 javascript/ajax - 单个脚本

php - Laravel PDO 异常

javascript - 达到特定字符数后如何防止输入文本区域?

php - AJAX 没有显示来自服务器请求的数据

javascript - 试图防止违约

php - 在 php 中管理 QUERY_STRING 的最佳方法是什么?