使用Facebook JS SDK注册

时间:2014-05-05 07:51:07

标签: javascript php facebook

我试图用Facebook JS SDK创建一个注册功能,但我得到了不同类型的记录,比我搜索了很多并且知道Facebook更新了他的应用政策,他们发布了v2 .0 for apps。

现在它在登录时发送不同的响应

Object {authResponse: Object, status: "connected"}
authResponse: Object
accessToken: "CAATZCeMqNYsABADVG3lHL1WYJiwnZASJIBzUtkfB4MFyFUC21g6myDeAP6WDSKkd8ZAnggffW5sIJzSDqmqxxvRgdeT7MKRXJ0L8Logg57PYwawEBSbgqz9I5qGU9Oo7uvaRN5MupjCfvo5w4bfCDZA5uvMkg7AK8DbwhXW4WoGHZBgG6EsmDDWZCnbVpUxWUZD"
expiresIn: 4562
signedRequest: "GXGqWXN9C5IzSy6jf2NOOQK7-ZK9JisKBCLEBHbaoIc.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUUE5c21GSWZ1dXoxMnpvNVV0MGdYYXNXclI1blJXZXh1NElGWHFFMHhnUDM3T0pScUJyaDhZeEo2YWt5aHlJYXUzc3UyU2hhZVczUzh1aHRheWJGX3N3aWtfSmVfUDRwallOeV9IX1JpTEs2ZWZKNlpETDQ5MC1OVUxKSzN4SWw2QmtfVXJER2ZrVE1uV1haZFY3LU02Y19xMjRwWjJUOEo2anB6djNGQ0Z0YUs5bW5fMVVobThycjRlVmlQOVVtVVNMZXA5NTg1X1ZhSHg2YkUyTEFBMUl3OUdfQXJnb2JRSldQaERXczlTSDdONzNzS1dlakQ3MDNsTmhpblhjbUt0RXU1NmpvTnVMODhvME9ZUXVtVEFfbzF4SEJ5YndSbDU4ekVrWEpMdVUtVFZfejY5UW9KekFMeFRCekNBUHBXcEQtVzUyVHlKd0tJNjBMTU5Qbjg0bCIsImlzc3VlZF9hdCI6MTM5OTI3NTgzOCwidXNlcl9pZCI6IjEwMDAwMDAxNTU5MzEwNyJ9"
userID: "100000015593107"
__proto__: Object
status: "connected"
__proto__: Object
}

与上一个SDK一样,我们使用

收到电子邮件
  

response.email

但是在新版本中,我们只获得了同样适用于应用的用户ID

  

response.authResponse.signedRequest

所以我搜索我们如何提取" signedRequest"因为我认为其余值肯定会在此代码中加密..

所以我用了

$signed_request= $_POST['maindata'];
        if (isset($signed_request))
        {
            $data_signed_request = explode('.', $signed_request); // Get the part of the signed_request we need.
            $jsonData = base64_decode($data_signed_request['1']); // Base64 Decode signed_request making it JSON.
            $objData = json_decode($jsonData, true); // Split the JSON into arrays.
        }
        print_r($objData);

但它再次发给我

Array
(
    [algorithm] => HMAC-SHA256
    [code] => AQA9smFIfuuz12zo5Ut0gXasWrR5nRWexu4IFXqE0xgP37OJRqBrh8YxJ6akyhyIau3su2ShaeW3S8uhtaybF_swik_Je_P4pjYNy_H_RiLK6efJ6ZDL490-NULJK3xIl6Bk_UrDGfkTMnWXZdV7-M6c_q24pZ2T8J6jpzv3FCFtaK9mn_1Uhm8rr4eViP9UmUSLep9585_VaHx6bE2LAA1Iw9G_ArgobQJWPhDWs9SH7N73sKWejD703lNhinXcmKtEu56joNuL88o0OYQumTA_o1xHBybwRl58zEkXJLuU-TV_z69QoJzALxTBzCAPpWpD-W52TyJwKI60LMNPn84l
    [issued_at] => 1399275838
    [user_id] => 100000015593107
)

我想知道如何获取电子邮件地址,如果您有任何想法,请告诉我们

1 个答案:

答案 0 :(得分:0)

您可以使用获取的access_token并使用Facebook API端点GET /me并传递access_token所述端点的响应将允许您获取该电子邮件的电子邮件地址与Facebook关联的地址仍然有效。