0

I have the follow code to login with Facebook:

// Include Facebook SDK

$this->facebook = new Facebook(array(
    'appId'  => 'APP ID',
    'secret' => 'APP SECRET',
    'cookie' => true
));

$uid = $this->facebook->getUser();
if($uid) {
    try {
        echo 'Done!';
    } catch (FacebookApiException $e) {
        echo $e;
        error_log($e);
    }
} else {
    $loginUrl = $this->facebook->getLoginUrl(array(
        'redirect_uri' => 'http://ogabrielsantos.com.br/dev/index.php?route=account/connect/facebook',
        'scope' => 'user_birthday'
    ));

    echo('<script>top.location.href = "' . $loginUrl . '";</script>');
}

UPDATE 1

I can authorize the App, but, after authorization, I can't get the logged user, EVER redirecting to

http://ogabrielsantos.com.br/dev/index.php?route=account%2Fconnect%2Ffacebook&state=RANDOM STATE&code=RANDOM CODE#_=_

I have tried:

  • Put the APP in a server;
  • Verify APP settings. All is correct;
  • Verify if url is the same at settings and code. All is ok;
  • My url is properly written: http://ogabrielsantos.com.br/dev/index.php?route=account/connect/facebook;
  • Reset APP SECRET.

Nothing worked.

You can check what happens going to:

http://ogabrielsantos.com.br/dev/index.php?route=account/connect/facebook

Facebook ask you to authorize the app to get your website, which is a safe information.

UPDATE 2

The follow code:

$this->facebook = new Facebook(array(
    'appId'  => $this->connect->config->get('facebook_api_key'),
    'secret' => $this->connect->config->get('facebook_app_secret'),
    'cookie' => true
));

$uid = $this->facebook->getUser();

echo'<pre>';
print_r($this->facebook);
echo'</pre>';
exit;

returns:

Facebook Object
(
    [sharedSessionID:protected] => 
    [appId:protected] => APP ID
    [appSecret:protected] => APP SECRET
    [user:protected] => 0
    [signedRequest:protected] => 
    [state:protected] => 
    [accessToken:protected] => APP ID|APP SECRET
    [fileUploadSupport:protected] => 
    [trustForwarded:protected] => 
)

I think the accessToken is wrong, returning my APP ID and SECRET with a pipeline separator.

UPDATE 3:

Now, I verify the code, but, always get Fatal error: Uncaught OAuthException: Error validating verification code

if(isset($_GET['code'])) {
    $api = $this->facebook->api('/oauth/access_token', array(
        'client_id' => APP ID,
        'redirect_uri' => 'http://ogabrielsantos.com.br/dev/index.php?route=account/connect/facebook',
        'client_secret' => APP SECRET,
        'code' => $_GET['code']
    ));

    echo'<pre>';
    var_dump($api);
    print_r($this->facebook->getUser());
    echo'</pre>';
    exit;
}

I have read some questions, which is similar but can't help-me.

Gabriel Santos
  • 4,934
  • 2
  • 43
  • 74

2 Answers2

1

Are you working on localhost? if yes it probably is the reason why. If not, check your app settings in developers.facebook.com/apps/APP_ID 1. You have to compare the urls written in your code with the ones you have in your app settings. 2. Another reason could be the that the urls in you app settings are not properly written, I remember having to add index.php at the end of my urls in Page Tab settings. Worked for me 3. Another option is to get a new APP_SECRET and update your code These options are from my personal experience, you issue could also be something else but you lose nothing trying

crisful
  • 11
  • 3
  • If you can't get a user id, it means that the issue is in your App settings. Unfortunately, I don't know what it is and I can only tell you about what I've experienced – crisful Sep 12 '12 at 10:44
1

The Facebook Sharing and Facebook Sign In functions are completely separate and each require their own app.

Are you using facebook sharing in the page you want the login working on?

Ref: http://www.ning.com/help/?p=8523

sergio
  • 997
  • 1
  • 11
  • 15