0

I use FB authorization through curl. Till now during a half an year All have been working well. But during the last couple of days I have found a message:

    [{"error":{"message":"This_authorization_code_has_been_used_","type":"OAuthException","code":100,"fbtrace_id":"HuUHKJv\/zGu"}}] =>
    $params = array(
        'client_id'     => FACEBOOK_ID,
        'redirect_uri'  => PATH_ROOT.REDIRECT_URI,
        'response_type' => 'code',
        'scope'         => 'email, user_birthday'
);
<a href="<?php echo FACEBOOK_OAUTH . '?' . urldecode(http_build_query($params))?>" class="facebook-icon-edit">Change</a>



callback:

if(isset($_GET['code']) and strlen($_GET['code']) > 100){

        $url = 'https://graph.facebook.com/oauth/access_token';
        $tokenInfo = null;

        $token_url = "https://graph.facebook.com/oauth/access_token?"
                . "client_id=" . FACEBOOK_ID . "&redirect_uri=" .      urlencode(PATH_ROOT.REDIRECT_URI)
                . "&client_secret=" . FACEBOOK_SECRET . "&code=" . $_GET['code'];
            $curl = curl_init();
            curl_setopt($curl,CURLOPT_URL, $token_url);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            parse_str(curl_exec($curl), $tokenInfo);
            curl_close($curl);
        echo "<pre>";
        print_r($tokenInfo);
        echo "</pre>";
///the three last rows get the message written above
thor
  • 21,418
  • 31
  • 87
  • 173
Vadik
  • 3
  • 4
  • Can you post some code that demonstrates what you are doing, and detail how it is being called, as well as anything pertinent about your server setup (eg any reverse proxies / redirects / rewriting etc)? – James Fry Mar 29 '17 at 11:43
  • The error message in your question is incomplete. Post the entire message. – Sloan Thrasher Mar 29 '17 at 11:47
  • If this started happening a few days ago, then it is most likely related to the API v2.2 shutdown. Since API v2.3, the format in which the access token is returned from that endpoint has changed, it now returns JSON. See also: http://stackoverflow.com/q/42994019/1427878 – CBroe Mar 29 '17 at 12:22
  • It`s strange but in developers.facebook.com i found version API v2.3 – Vadik Mar 29 '17 at 13:19
  • it long before in account in developers.facebook.com as version API v2.3 was set – Vadik Mar 29 '17 at 14:30

1 Answers1

0

The source of error was that, so far, responce from facebook was a string. and now bacame as a json one. so I change

parse_str(curl_exec($curl), $tokenInfo);

to

$tokenInfo= curl_exec($curl);
$tokenInfo = json_decode($tokenInfo, true); 

message: this authorization code has been used

this message was appeared may be for a reason of several applying to one page

Vadik
  • 3
  • 4