facebook connect api
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 →">
</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.
精彩评论