0

如何使用 facebook 注册插件获取在我的网站上注册的 facebook 用户的用户 ID。

Graph Api 表示每个 facebook 对象都有一个唯一的 ID。

我想知道一种获取此 ID 的方法。

注册插件的json代码为:

<iframe src='http://www.facebook.com/plugins/registration.php?
                            client_id=325340244194060&
                                 redirect_uri=http://www.pingcampus.com/facebook_registration_plugin/store_user_data.php&
                            fields=[
    {
        "name": "name"
    },
    {
        "name": "email"
    },
    {
        "name": "gender"
    },
    {
        "name": "birthday"
    },
     {
        "name": "captcha"
    }
    ]'
                            scrolling="auto"
                            frameborder="no"
                            style="border:none"
                            allowTransparency="true"
                            width="500"
                            height="800"

             >
                    </iframe>   

我用来获取详细信息的 PHP 代码是:

   <?php ob_start();
    define('FACEBOOK_APP_ID', '325340244194060');
    define('FACEBOOK_SECRET', '2ab5cb734f39d8417569cc7be7a0e89a');





    // No need to change function body
    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, '-_', '+/'));
    }

    if ($_REQUEST) {
        $response = parse_signed_request($_REQUEST['signed_request'],
                        FACEBOOK_SECRET);


        /*
          "<pre>";
        print_r($response);
          "</pre>"; // Uncomment this for printing the response Array
        */





        $name = htmlentities($response["registration"]["name"]);
        $email = htmlentities($response["registration"]["email"]);
        $gender = htmlentities($response["registration"]["gender"]);
        $dob = htmlentities($response["registration"]["birthday"]);
        $phone = htmlentities($response["registration"]["phone"]);

} else {
        echo '$_REQUEST is empty';
    }
    ?>
4

2 回答 2

0

根据https://developers.facebook.com/docs/plugins/registration/ user_id 在 signed_request 数据上。

I don't know PHP, but based on your above code and the information from the registration documentation, it should look something like this:

.....
$name = htmlentities($response["registration"]["name"]);
.....
$id = $response["user_id"];
于 2012-06-12T22:23:46.313 回答
-1

没有办法做到这一点,相反,一旦用户通过您的应用程序注册或登录 Facebook,您就需要将用户的数据保存在您的数据库中。

于 2012-06-11T20:43:31.353 回答