开发者

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/

  1. Setup new App here
  2. Download the PHP SDK here
  3. Copy & Paste the code you'll find here into a file called index.php
  4. 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:

  1. Web Site -> Site URL -> http://so.devilmaycode.it/facebook/
  2. Web Site -> Site Domain -> so.devilmaycode.it
  3. Facebook Integration -> Canvas URL -> http://so.devilmaycode.it/facebook/

Requiriment

  1. PHP5
  2. 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',
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜