facebook的getUser()在粉丝页面选项卡iframe仅在IE上显示内部服务器错误 [英] facebook getUser() in fan page tab iframe shows internal server error only on IE
问题描述
我在Facebook页面选项卡上使用了一个使用getUser的应用程序,以便我可以在Chrome和Firefox上获得该用户的facebook id,而不是IE。我试图清除缓存几次!这是我正在做的(这是codeigniter框架)
I have an application on facebook page tab that uses the getUser so that I can get the facebook id of that user it works fin on both Chrome and Firefox but not on IE. I tried to clear cache several times! here is what I am doing (this is codeigniter framework)
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Register extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('facebook', $this->config->item('fb_config'));
$this->load->library('Form_validation');
$this->load->library('session');
$this->load->model('users_model', 'users');
}
public function index() {
$user_id = $this->facebook->getUser();
if ($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$user_profile = $this->facebook->api('/me', 'GET');
$data['fb_id'] = $user_profile['id'];
$this->session->set_userdata('fb_id', $data['fb_id']);
$users = $this->users->get_by_fb_id_register($data['fb_id'], array('full_name', 'age', 'email', 'phone_number'));
// not first time
if ($users != 0 && $users->num_rows() < 1) {
$data['full_name'] = $user_profile['name'];
$birthDate = explode("/", $user_profile['birthday']);
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y") - $birthDate[2]) - 1) : (date("Y") - $birthDate[2]));
$data['age'] = $age;
$data['email'] = $user_profile['email'];
} else {
$data = $users->row_array();
}
} catch (FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $this->facebook->getLoginUrl(
array(
'scope' => 'email, user_birthday, publish_actions, publish_stream', //read_stream, friends_likes, user_likes
// 'redirect_uri' => $this->config->item('fan_page_app_link'), //the url to go to after a successful login
));
echo '<script> window.top.location.href = "' . $login_url . '"; </script>';
exit;
}
} else {
// No user, print a link for the user to login
$login_url = $this->facebook->getLoginUrl(
array(
'scope' => 'email, user_birthday, publish_actions, publish_stream', //read_stream, friends_likes, user_likes
'redirect_uri' => $this->config->item('fan_page_app_link'), //the url to go to after a successful login
));
echo '<script> window.top.location.href = "' . $login_url . '"; </script>';
exit;
}
}
?>
给出错误500的URL:
the url that gives error 500:
https://www.facebook.com/dialog/oauth?client_id=1397280120532513&redirect_uri=https%3A%2F%2FMYWEBSITE.com%2Fmatchgame%2Fregister&state=bc353f470176d5a62995722808e3f406&sdk=php-sdk-3.2.3&scope=email%2C+user_birthday%2C+publish_actions%2C+publish_stream
我不知道这是否有任何错误,但我做了以下:
I don't know if this has to do anything with the error but I did the following:
我对facebook.php文件的唯一变化是将其重命名为Facebook.php并添加此行
the only change that i did to the facebook.php file is rename it to Facebook.php and added this line
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
到 __构造,因为我收到此错误
Invalid or no certificate authority found, using bundled information
不管所有三个文件facebook.php,base_facebook.php和fb_ca_chain_bundle.crt都在同一个文件夹中,库文件夹
althoug all three files facebook.php, base_facebook.php and fb_ca_chain_bundle.crt are all in the same folder, the libraries folder
在html文件的顶部,标题这个代码:
at the top of the html file after the header this code:
<script type="text/javascript">
function NotInFacebookFrame() {
return top === self;
}
function ReferrerIsFacebookApp() {
if (document.referrer) {
return document.referrer.indexOf("apps.facebook.com") != -1;
}
return false;
}
if (NotInFacebookFrame() || ReferrerIsFacebookApp()) {
top.location.replace("<?php echo $this->config->item('fan_page_app_link'); ?>");
}
</script>
所以如果用户直接从网站访问应用程序,他将被重定向到facebook网站。
so that if the user is accessing the application directly from the site he will be redirected to the facebook website.
更新
如果我直接使用此网址从我的网站输入应用程序 https://MYWEBSITE.com/matchgame/register 然后我从Facebook返回应用程序是作品如果我从Facebook进入应用程序,那么它的接缝有一些Cookie被阻止。
If i enter the application directly from my website using this url https://MYWEBSITE.com/matchgame/register then I head back to the application from the facebook is works, it seams there is some cookie that is being blocked if i enter the application from the facebook!!!
推荐答案
我终于找到了解决方案,显然所有我需要的IE接受跨浏览器cookie是一个P3P策略头,所有我做的,因为这是一个PHP应用程序是在任何页面输出之前的以下代码:
I finally found the solution, apparently all I needed for IE to accept cross-browser cookies is a P3P policy header, all I did for since this is a PHP apps is the following bit of code prior to any page output:
header('p3p: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"');
或头块中的这个
<meta http-equiv="P3P" content='CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"' />
如果您使用除PHP 之外的任何,或者您喜欢元标记超过PHP代码。
if you are using anything other than PHP or if you prefer meta tag over PHP code.
这篇关于facebook的getUser()在粉丝页面选项卡iframe仅在IE上显示内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!