user3590206
user3590206

Reputation: 1

Wrong answer cURL facebook debug_token

I'm trying to login using Facebook manually, using cURL. The data returns normally, but the User data is not correct (the user_id is not the same as the logged in user) ... Anyone know the reason of the erroneous data coming?

My code:

$code = "MY PARAM URL";

//Getting my access_token to debug_token
$retornoAccess = $this->getCurl(array('url' =>
'https://graph.facebook.com/oauth/access_token?client_id=MY_APP_ID&redirect_uri=MY_URI&client_secret=MY_SECRET&code=' . $code . '#_=_'));


//Getting infos: user_id, app_id, is_valid, etc
$access_debug = explode('&', $retornoAccess);
$access_debug = array_pop(explode('=', $access_debug[0]));
$dadosAcesso = $this->getCurl(array('url' => 'https://graph.facebook.com/debug_token?input_token=' . $access_debug . '&access_token=' . $options['facebook']['app']['accesstoken']));

public function getCurl($params)
{
    if(is_array($params)){
        $header[] = 'Expect:';
        $header[] = 'Content-Type: application/json';

        $ch = curl_init();

        $options = array();
        $options[CURLOPT_URL] = $params['url'];
        $options[CURLOPT_HTTPHEADER] = $header;
        $options[CURLOPT_SSL_VERIFYPEER] = false;
        $options[CURLOPT_RETURNTRANSFER] = true;
        $options[CURLINFO_HEADER_OUT] = true;

        curl_setopt_array($ch, $options);
        $ret = curl_exec($ch);
        $err = curl_error($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);
        return json_decode($ret, true);
    }
    return false;
}

Upvotes: 0

Views: 226

Answers (1)

Tobi
Tobi

Reputation: 31479

You're probably seeing an app-scoped user_id. This is by design with Graph API v2-0. See my answer at Weird Facebook ids for details.

You can verify this if you use the Graph Explorer with your respective app.

Upvotes: 1

Related Questions