簡體   English   中英

帶有身份驗證令牌的Facebook Connect API問題

[英]Facebook Connect API issue with authentication token

我已經根據文檔在下面實現了以下代碼,可以連接並顯示用戶ID ...

<?php

define('FACEBOOK_APP_ID', '87939462878');
define('FACEBOOK_SECRET', '1ab6346bc51329831998985aba200935');

function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $application_secret) != $args['sig']) {
    return null;
  }
  return $args;
}

$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);

?>

<?php if ($cookie) { ?>
      Your user ID is <?= $cookie['uid'] ?>
    <?php } else { ?>
      <fb:login-button show-faces="true" perms="email,user_birthday,user_location"></fb:login-button>
    <?php } ?>


<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
      FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true,
               cookie: true, xfbml: true});
      FB.Event.subscribe('auth.login', function(response) {
        window.location.reload();
      });
    </script>

<?php
$user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']))->id;
print_r($user);
?>

但是,如果我使用:

$user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?wrap_access_token=' .
    $cookie['oauth_access_token']))->me; //or $cookie['access_token']))->me;
register_user($user->id, $user->email, $user->name, $user->username,
              $user->birthday_date);

要獲取電子郵件地址,我總是收到file_get_content錯誤。 我也收到錯誤消息,說它無法識別register_user函數。 我覺得我已經接近了! 如果可以的話請幫助,謝謝!

我不熟悉您正在使用的具有register_user的庫,但是是否有任何原因不使用Facebook Connect PHP SDK? 您可以在http://github.com/facebook/php-sdk上下載它,並且它的示例包含獲得具有擴展權限的auth令牌,然后提取您似乎想要的所有用戶信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM