编辑:请参阅这张图片:http://trackauthoritymusic.com/wwwroot/images/fb-issue-bug.jpg。
自从我于 4 月 24 日发布原始帖子以来,我一直把这个错误放在一边:....
经过3天的反复试验和研究:
我的环境: 使用 facebook sdk 3 和 CodeIgniter 2 的 LAMP
登录码:
$CI->load->library('facebook', array("appId"=>APP_ID, "secret"=>APP_SECRET)); $this->visitor['access_token'] = $CI->facebook->getAccessToken(); $fb_id = $CI->facebook->getUser(); var_dump($CI->facebook); // 见上图 var_dump($fb_id); // == 0 如果($fb_id && $fb_id > 0){ $temp = $CI->users->getUserByFb($fb_id); 如果 (!$temp) { $this->insertFBUser($fb_id); $this->visitor['redirect'] = "?prompt=newfb"; } 别的 { $this->visitor = array_merge($this->visitor, $temp); if (isset($this->visitor['user_allowed']) && $this->visitor['user_allowed'] == 0) { $CI->users->updateUser(array("user_allowed" => 1), $this->visitor['user_id']); } } } 别的 { array_push($this->errors, $CI->input->get_post("error_msg", false)); array_push($this->errors, $CI->input->get_post("error_code", false)); array_push($this->errors, $CI->input->get_post("error_reason", false)); array_push($this->errors, $CI->input->get_post("error", false)); array_push($this->errors, $CI->input->get_post("error_description", false)); if ($CI->input->get_post("autoclose", false) == true) { array_push($this->errors, "javascript stackoverflow 的编码很奇怪,但基本上改变了弹出窗口的主题标签,因此父页面会自动关闭它"); } var_dump($this->错误); 死(“虚无”); }
研究与调试:
这篇文章也描述了我的问题,但解决方案不起作用:stackoverflow.com/questions/8587098/suddenly-getuser-became-to-return-0-php-3-1-1-sdk与或此页面上的 DROP_QUERY_PARAMS 数组中没有尾随逗号。
Facebook 在网址、帖子或会话中没有向我发送任何错误消息,并且很好地抓取了我的页面
几天前一切都运行良好,我对此代码做了很少的更改。
现在无论我使用http还是https都登录失败
弹出链接打开于:
www.facebook.com/dialog/oauth?client_id=222912307731474&redirect_uri=https%3A%2F%2Ftrackauthoritymusic.com%2Fmanage%2Fusers%2Flogin%3Fautoclose%3Dtrue&state=4522cb9da5bf5107d690a22eee6c5a2e&scope=email&display=popup 同时成功重定向到我想要的登录网址状态和代码参数显然有效: trackauthoritymusic.com/manage/users/login?autoclose=true&state=4522cb9da5bf5107d690a22eee6c5a2e&code=AQBfSkI4y_VxhCuF3coVvNmjetdGZjugyFv0UsLlKt5sR5MEGdY8KqpDXZKvqHTGa SHhzY4pHXuR_zmilkwmoQ5y6M9jh15GPI6DXz5E2fSBizAVlrlebriNGcNZb4DRaDFK8cxPJoa9xB2ERuimtuizmlZERNa8hwJxLXtztqkWWhkLFCaGjQvAyyf5jJRkuoztmvfKDIZz3W9lslM6fk_m
但此时,sdk 无法获取任何访问令牌或 facebook 会话数据。
请帮忙!
我通过使用 Facebook SDK 中的 codeigniter 输入库来获取代码/令牌和所有 $_GET/$_POST/$_REQUEST 全局变量来修复此问题。
查看 facebook sdk 上的 git diff。我仍然不确定我做了什么来打破这个。 OAuth/登录在某个时间点之前一直工作正常。我确信这不仅仅是 codeigniter 上偶尔清除全局变量的一些竞争条件
@@ -490,10 +490,11 @@
*/
public function getSignedRequest() {
if (!$this->signedRequest) {
- if (!empty($_REQUEST['signed_request'])) {
- $this->signedRequest = $this->parseSignedRequest(
- $_REQUEST['signed_request']);
- } elseif (!empty($_COOKIE[$this->getSignedRequestCookieName()])) {
+ $CI = & get_instance();
+ $signed_request = $CI->input->get_post("signed_request");
+ if (!empty($signed_request)) {
+ $this->signedRequest = $this->parseSignedRequest($signed_request);
+ } else if (!empty($_COOKIE[$this->getSignedRequestCookieName()])) {
$this->signedRequest = $this->parseSignedRequest(
$_COOKIE[$this->getSignedRequestCookieName()]);
}
@@ -691,15 +692,18 @@
protected function getCode() {
- if (isset($_REQUEST['code'])) {
- if ($this->state !== null &&
- isset($_REQUEST['state']) &&
- $this->state === $_REQUEST['state']) {
-
+ $CI = & get_instance();
+ $code = $CI->input->get_post("code");
+ if (!empty($code)) {
+ $state = $CI->input->get_post("state");
+ if ($this->state !== null && $state && $this->state === $state) {
// CSRF state has done its job, so clear it
$this->state = null;
$this->clearPersistentData('state');
- return $_REQUEST['code'];
+ return $code;
} else {
self::errorLog('CSRF state token does not match one provided.');
return false;
$params['access_token'] = $this->getAccessToken();
}