繁体   English   中英

单击fblogin按钮后,将在SSL URL中打开Facebook应用

[英]Facebook app opening in SSL URL once fblogin button is clicked

我是Facebook应用程序的新手。 直到现在,当我单击fb登录按钮时,一切都很好。 通常,它将要求我获得许可,然后将我重定向到actions.php。 现在,它将把我重定向到facebook画布之外的SSL URL。 因此,我现在看到的是我的普通网页不再位于facebok页面中。

这是显示我的主页的索引代码和action.php:

index.php

    <?php
    error_reporting(0);
    include 'library.php';
    ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>HELP</title>
    <script type="text/javascript">
    window.fbAsyncInit = function() {
        FB.init({
        appId      : '*************', // replace your app id here
        channelUrl : '//<domain_name>/bacardi-test/channel.html',
        status     : true,
        cookie     : true,
        xfbml      : true
        });
    };
    (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));


        function FBLogin(){
        FB.login(function(response){
            if(response.authResponse){
                window.top.location = "actions.php?action=fblogin";
            }
        }, {scope: 'email,user_likes,user_birthday'});
    }

    </script>
    </head>
    <body>
    <div id="fb-root"></div>
    <img src="assets/img/bacardi/facebook-connect.png" alt="Fb Connect" title="Login with facebook" onclick="FBLogin();"/>
    </body>
    </html>

actions.php

<?php
include 'library.php';

$action = $_REQUEST["action"];
switch($action){
    case "fblogin":
    include 'src/facebook.php';
    $appid  = "**************";
    $appsecret  = "************";
    $facebook   = new Facebook(array(
        'appId' => $appid,
        'secret' => $appsecret,
        'cookie' => TRUE,
    ));

    $fbuser = $facebook->getUser();

    if ($fbuser) {
        try {
            $user_profile = $facebook->api('/me');
        }
        catch (Exception $e) {
            echo $e->getMessage();
            exit();
        }
        # Account ID
        $user_fbid  = $fbuser;

        # Account Bday
        $user_bday = $user_profile['user_birthday'];

        # Account Email
        $user_email = $user_profile['email'];

        # Account firstname
        $user_fname = $user_profile['first_name'];

        # Account lastname
        $user_lname = $user_profile['last_name'];

        # Accounr image url
        $user_image = "https://graph.facebook.com/".$user_fbid."/picture?type=large";

        $check_select = mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE email = '$user_email'"));
        if($check_select == 0){
            mysql_query("INSERT INTO `users` (fb_id, fname,lname, email, image, birthday,postdate)
            VALUES ('$user_fbid', '$user_fname', '$user_lname', '$user_email', '$user_image', '$user_bday',now())");
        }
    }   
    break;
    }

?>

似乎window.top.location打破了Facebook的iframe。 我正在研究许可的自动提示,而不是按某种方式更改它的Button。 现在它已经在工作了。 我只是将window.top.location更改为window.location.href。 感谢大家的时间阅读我的问题。

暂无
暂无

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

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