1
votes

I try to get a access token from facebook with my (in creation) facebook class. But it tell me that i have a "You are using an incompatible web browser". How can i pass this error ? I tried to set an http_user_agent, but it doesn't work.

Thanks for your help!

Between, i don't want the facebook sdk, i want to understand all what i do. Can it be possible ?

$_COOKIE['evo-fbAuth'] = false;
$_SERVER['HTTP_USER_AGENT'] = "Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2";

class facebook{

    private $_appID;
    private $_appSECRET;
    private $_code = null;
    private $_accesstoken = null;
    private $_urlAuth = 'https://www.facebook.com/dialog/oauth';

    function __construct($appID,$appSECRET){
        $this->_appID = $appID;
        $this->_appSECRET = $appSECRET;

    }

    public function fbauth($param){
        if(!isset($_GET['code'])){
            if(isset($param['redirect_uri']) && isset($param['scope'])){
                $urlAuth = $this->_urlAuth;
                $urlAuth .= '?client_id='.$this->_appID;

                $param['redirect_uri'] = $param['redirect_uri'];

                foreach($param as $key => $value){
                    $urlAuth .= '&'.$key.'='.$value;
                }

                if(!$this->authCookie()) header('Location: '.$urlAuth);
            }else{
                return false;
            }
        }else{
            $this->_code = $_GET['code'];
            $this->getAccessTok($param);
        }
    }

    private function getAccessTok($param){
        if($this->_code !== null){
            $urlTok = $this->_urlAuth.'/access_token';
            $urlTok .= '?client_id='.$this->_appID;
            $urlTok .= '&redirect_uri='.$param['redirect_uri'];
            $urlTok .= '&client_secret='.$this->_appSECRET;
            $urlTok .= '&code='.$this->_code;

            print_r(file_get_contents($urlTok));
        }
    }

    private function authCookie(){
        if($_COOKIE['evo-fbAuth'] == true){
            return true;
        }else{
            setcookie('evo-fbAuth',true,600);
            return false;
        }
    }

}

$fb = new facebook('**************','****************************');

$param = array(
            'redirect_uri'=>'http://localhost/facebook-auth/MOI_facebook.class.php',
            'scope'=>'read_stream,publish_stream,publish_actions,manage_pages,email,user_birthday'
        );

$fb->fbauth($param);
1

1 Answers

2
votes

This is because you using wrong URL for access_token retrieval in getAccessTok function:

// URL you use is $this->_urlAuth.'/access_token'
https://www.facebook.com/dialog/oauth/access_token

// But should be
https://graph.facebook.com/oauth/access_token