开发者

facebook connect api

开发者 https://www.devze.com 2023-03-07 02:18 出处:网络
Is it possible to use the facebook connect api to just grab some information and use it with a customized form?

Is it possible to use the facebook connect api to just grab some information and use it with a customized form? Because facebook register api shows a pre-filled form, how to开发者_JS百科 get these data and use them with another form Thanks


You should use the Facebook PHP SDK (see on github). Here is how you would do that.

require "facebook.php";

$facebook = new Facebook(array(
    'appId'  => '...',
    'secret' => '...',
));

$user = $facebook->getUser();

if ($user) {
  try {
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    $user = null;
  }
}

Here, if $user is not null, the user is logged in and you have his personal data in the array $user_profile.

Here is an example of the form you can generate pre-filled with some Facebook data :

<?php if ($user): ?>
    <form action="#" method="get">
        <input type="text" name="name" value="<?php echo $user_profile['name'] ?>">
        <input type="submit" value="Continue &rarr;">
    </form>
    <a href="<?php echo $facebook->getLogoutUrl() ?>">Logout of Facebook</a>
<?php else: ?>
    <a href="<?php echo $facebook->getLoginUrl() ?>">Login with Facebook</a>
<?php endif ?>

See the example of the Facebook PHP SDK for more detail on the flow.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号