0

我有一个从页面选项卡运行的应用程序。登录到应用程序是通过 Javascript 完成的。

function facebooklogin() {
   FB.getLoginStatus(function (response) {
      if (response.status === 'connected') {
         //user authorized
         //SubmitLogin(response);
         fbid = response.authResponse.userID; //valid response returned
         token = response.authResponse.accessToken; //valid response returned
         SubmitLogin();
      }
      else if (response.status === 'not_authorized') {
         FB.login(function (response) {
            if (response.authResponse) {
               // user authorized
               //SubmitLogin(response);
               fbid = response.authResponse.userID; //valid response returned
               token = response.authResponse.accessToken; //valid response returned
               SubmitLogin();
            } else {
               // user cancelled
               alert("User authorization is required for taking part in this promo.");
            }
         }, {
            scope: 'user_about_me,user_birthday,user_checkins,user_hometown,user_location,publish_stream,email'
         });
      } else {
      // the user isn't logged in to Facebook.
      }
   });
}

function SubmitLogin() {
   //$("#token").val(response.authResponse.accessToken);
   //$("#fbid").val(response.authResponse.userID);
   //$("#login_form").submit();
   $("#print_me").prop("href", "printable.php?fbid=" + fbid);
   if (fbid != "") {
      $.post("submit_user.php", "fbid=" + fbid + "&token=" + token, function(msg) {
         var spl = msg.split("|");

         if (spl.length == 3) {
            //this part isn't an issue since the code never reaches it
            post_wall();
            $("#share_section").css({display: "none"});
            $("#reward_section").css({display: "block"});
            FB.Canvas.setSize();

            $("#coupon_printout").html(spl[0]);
            $("#qr_holder").html(spl[1]);
            $("#expiration").html(spl[2]);
         }
         else {
            //code always lands here because of the error in the php script
            alert(msg);
         }
      });
   }
   else {
      alert("You have not signed in to this app. If you did not see a sign in request, you may need to disable your pop-up blocker.");
   }
}

当我回显返回值时,用户的 FacebookID 和访问令牌恢复正确。然后我将这些传递给登录到应用程序的 PHP 脚本。到目前为止一切正常。

require 'facebook.php';
$facebook = new Facebook(array(
'appId' => /*my app ID*/,
'secret' => /*my app secret*/,
'cookie' => true
));

$signedRequest = $facebook->getSignedRequest(); //is blank

$user_id = $facebook->getUser(); //user's FacebookID gets returned
$user_profile = $facebook->api('/me','GET'); //OAuth error gets thrown

这是我的全部 PHP 代码,直到在 Safari 上引发 OAuth 错误的部分。我尝试打印出我通过 post 传递的访问令牌,它出现了。但是,getAccessToken() 会打印出不同的值。

该区域的其他浏览器未出现错误。

编辑:将文件移动到不同的服务器,它开始适用于某些浏览器,而在其他浏览器中没有区别。

4

0 回答 0