简体   繁体   English

带有身份验证令牌的Facebook Connect API问题

[英]Facebook Connect API issue with authentication token

I have implemented the following code below according to the documentation and can get it to connect and display user id... 我已经根据文档在下面实现了以下代码,可以连接并显示用户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);
?>

However, if I use: 但是,如果我使用:

$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);

to get the email address, I keep getting file_get_content errors. 要获取电子邮件地址,我总是收到file_get_content错误。 I also get errors saying it doesn't recognize the register_user function. 我也收到错误消息,说它无法识别register_user函数。 I feel that I'm close!! 我觉得我已经接近了! Please help if possible, thanks! 如果可以的话请帮助,谢谢!

I'm not familiar with the library you're using that has register_user, but is there any reason you aren't using the Facebook connect PHP SDK? 我不熟悉您正在使用的具有register_user的库,但是是否有任何原因不使用Facebook Connect PHP SDK? You can download it at http://github.com/facebook/php-sdk and it has examples for both obtaining the auth token with extended permissions and then pulling all the user information you seem to want. 您可以在http://github.com/facebook/php-sdk上下载它,并且它的示例包含获得具有扩展权限的auth令牌,然后提取您似乎想要的所有用户信息。

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

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