2012-06-11 73 views
0

如何獲取正在我的網站上使用Facebook註冊插件註冊的Facebook用戶的用戶標識。如何獲取通過註冊社交插件在我的網站上註冊的用戶的用戶標識

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'; 
    } 
    ?> 

回答

0

根據https://developers.facebook.com/docs/plugins/registration/ user_id位於signed_request數據上。

我不知道PHP,但根據您上面的代碼,並從註冊文件中的信息,它應該是這個樣子:

..... 
$name = htmlentities($response["registration"]["name"]); 
..... 
$id = $response["user_id"]; 
+0

我之前想通了,但答案是正確的,可幫助別人! – user1446599

-1

沒有這樣做的方式,而不是你需要一旦用戶註冊或通過您的應用程序與Facebook登錄,即可將用戶的數據保存在數據庫中。

相關問題