Facebook login/connect help - PHP
I am having problems with Facebook connect. Once I have the connect with Facebook button how do i retrieve the info with php?
There are loads of examples in developer.facebook.com but I couldn't get any of them to work.
Is it POST or GET o开发者_如何学Cr what? (I'm kinda new to php... )
Thanks.
- DEMO: http://so.devilmaycode.it/facebook-login-connect-help-php/
- Setup new App here
- Download the PHP SDK here
- Copy & Paste the code you'll find here into a file called
index.php
- Edit the first lines of the code above and provide the needed informations like below:
require 'sdk/facebook.php'; //the path to the downloaded PHP SDK
$facebook = new Facebook(array(
'appId' => '105810212821284', //App ID you find once created the app
'secret' => '3d6fdaa377cd4ca9...', //Secret Key you find once created the app
'cookie' => true,
));
you have done ;)
Application Settings:
- Web Site -> Site URL ->
http://so.devilmaycode.it/facebook/
- Web Site -> Site Domain ->
so.devilmaycode.it
- Facebook Integration -> Canvas URL ->
http://so.devilmaycode.it/facebook/
Requiriment
- PHP5
- CURL Lib
Check if you have the requirement
<? echo phpinfo(); ?>
Demo Source
- http://pastebin.com/KyQ3CHV0
Use https://github.com/facebook/php-sdk/
Example
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
Display the data
echo $me['email']
http://developers.facebook.com/docs/reference/api/user/
More info about Graph API
To get the email or aditional data from users, you need to request it first(if not you only can get the basic data, like name / picture or only the public data), check the api facebook file in the function called "getLoginUrl".
'api_key' => $this->getAppId(),
'cancel_url' => $currentUrl,
'display' => 'page',
'req_perms' => 'email', <------------- email
'fbconnect' => 1,
'next' => $currentUrl,
'return_session' => 1,
'session_version' => 3,
'v' => '1.0',
精彩评论