我对我的 Facebook 应用程序的授权有疑问。当我在本地 Web 服务器上正常运行我的应用程序时,进程如下所示:
**Get facebook user->If user is not logged on -> Redirect user on facebook login page**
**Get facebook user->If user is logged on -> Redirect user to authorize my facebook application->everything goes right without problems**
当我使用 iframe 在 facebook 上托管我的应用程序时,第二个进程不起作用(用户永远不会显示授权窗口),并且出现以下异常:
Error validating access token: User xxxxxxx has not authorized application xxxxxxx.
我正在使用 CodeIgniter PHP 框架,这是我的 PHP 代码:
$this->load->library('facebook');
$user = null;
$user_profile = null;
$user = $this->facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$access_token = $this->facebook->getAccessToken();
$user_profile = $this->facebook->api($user);
}
catch (FacebookApiException $e) {
show_error(print_r($e, TRUE), 500);
}
}
else{
$data = array(
'redirect_uri' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx','scope'=>'email');
$access_token = $this->facebook->getAccessToken();
redirect($this->facebook->getLoginUrl($data));
}
$data['facebook']=$user_profile;
$this->load->view('templates/header');
$this->load->view('pages/prijavaKlasicnoFacebook', $data);
$this->load->view('templates/footer');
}