我尝试用我的(在创作中)facebook类从facebook获取访问令牌。但它告诉我,我有一个“你正在使用不兼容的网络浏览器”。我怎么能传递这个错误?我试图设置一个http_user_agent,但它不起作用。
感谢您的帮助!
之间,我不想要facebook sdk,我想了解我所做的一切。可以吗?
$_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);
答案 0 :(得分:2)
这是因为您在access_token
函数中使用错误的网址进行getAccessTok
检索:
// 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