Marek N.
Marek N.

Reputation: 21

Facebook OAuth 2.0 Issues

I'm trying to integrate my web based application with facebook.

First of all, I created page login/facebook which redirects user to the URL: https://www.facebook.com/dialog/oauth?client_id=MY_ID&redirect_uri=https://www.domain.com/connect/facebook&scope=email,user_about_me,user_location

So far so good. Have no problems at this stage.

If user authorize my application, he gets redirected to the www.domain.com/connect/facebook page. On this page I create user in my database using data returned by FB or just authorize user and create session. On this step I have issues. When I use code from the examples from Facebook Developers Help Page everything works:

$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $this->app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
    . $this->secret . "&code=" . $code;
$access_token = file_get_contents($token_url);
$graph_url = "https://graph.facebook.com/me?" . $access_token;
$user_object = json_decode(file_get_contents($graph_url));

When I use following snippet everything works perfectly. However I prefer to use PHP-SDK and having problems. When I use following snippet:

$session = $this->facebook->getSession();
var_dump($session);
            if( $session )
            {
                try
                {
                    $uid = $this->facebook->getUser();
                    $me = $this->facebook->api('/me');

                    var_dump('me');
                }
                catch (FacebookApiException $e)
                {
                    error_log($e);
                }
            }

session is null. Anybody has any suggestions?


Edit
After having some fun with PHP-SDK I noticed some funny stuff: When I use SDK getLoginUrl() method to generate redirect URL, it seems to be partially working.

$login_url = $this->facebook->getLoginUrl(
        array(
            'api_key' => $this->api_key,
            'req_perms' => 'email,user_work_history,user_about_me,user_location',
            'next' => 'https://www.domain.com/connect/facebook'
        )
    );

Now when users authorizes my app, he's being redirected to correct page with some params, URL looks like: https://www.domain.com/connect/facebook?session={"session_key"%3A"11111111111-111111111"%2C"uid"%3A"11111111"%2C"expires"%3A0%2C"secret"%3A"111111111"%2C"base_domain"%3A"domain.com"%2C"access_token"%3A"1111111|222222.0-33333|sdvsdvsdvsdvsdv"%2C"sig"%3A"gsdbsdbsdbsdbsdbsdbsdb"}

Anyone has any idea why it's not hashes or it shouldn't?

Cheers, Marek

Upvotes: 2

Views: 1174

Answers (1)

dragonjet
dragonjet

Reputation: 1006

You might wanna add:

'canvas' => 0,
'fbconnect' => 1

in your getLoginUrl array of parameters.

Upvotes: 1

Related Questions