1

在我说我想说的东西,我GOOGLEd了很多,有很多页面找到(包括许多这样的问题)与各种解决方案......但我已经尝试过他们每一个,但不幸的是他们都没有为我工作

与facebook-php-sdk我想登录一个用户。 最初几次它工作得很好(2到3天前)。今天,当我开始再次与我的项目工作,它不再工作。每当我尝试登录用户$facebook->getUser() is returning 0。但3天后它工作。

我已经使用这里给出:: developers.facebook.com代码,是的,我已经做了一些修改那些在下面

我的代码:: 0auth_provided_by_facebook.php

include_once $_SERVER['DOCUMENT_ROOT'].'dist/facebook-php-sdk/src/facebook.php'; 

$config = array(
    'appId' => '***********', 
    'secret' => '*********', 
    'allowSignedRequest' => false, // optional but should be set to false for non-canvas apps 
'cookie' => true, 
'oauth'  => true 
); 

$facebook = new Facebook($config); 
$user_id = $facebook->getUser(); 
if($user_id) { 
    try { 

     $user_profile = $facebook->api('/me','GET'); 

    } catch(FacebookApiException $e) { 
    $login_url = $facebook->getLoginUrl(array(
    scope'=>'email,user_location,user_photos,publish_actions,publish_stream,basic_info', 
    'redirect_uri' => 'http://localhost/dist/include/0auth_provided_by_facebook.php' 
    )); 
    echo '<a href="' . $login_url .'"> PLEASE CLICK HERE </a>'; 
    error_log($e->getType()); 
    error_log($e->getMessage()); 
    } 
} else { 

    $login_url = $facebook->getLoginUrl(array(
    'scope'  => 'email,user_location,user_photos,publish_actions,publish_stream,basic_info', 
    'redirect_uri' => 'http://localhost/dist/include/0auth_provided_by_facebook.php' 
    )); 
    echo '<a href="' . $login_url .'"> PLEASE CLICK HERE </a>'; 

} 

OUTPUT给出完整的代码:getUser()总是返回0.


我的登录过程如下工作如何描述:点击<a href="login_fb">Login using fb </a>控制后

去我localhost/dist/index.php现在我的index.php include上述wriiten代码是在不同的目录localhost/dist/include/0auth_provided_by_facebook.php从这个文件我处理一切。在成功登录Facebook的回报价值的失败here.and然后在成功登录的用户再次重定向到家里


现在,这里是我的应用程序设置的,他完整列表,我启用或禁用或更改

1. App Domains : blank(according to the answer) 
2. Site URL : `http://localhost/dist/include/0auth_provided_by_facebook.php?` 
3. Native or desktop app? Disabled 
4. Deauthorize Callback URL : `http://localhost/dist/include/0auth_provided_by_facebook.php?` 
5. Social Discovery : enabled 
6. Client OAuth Login : enabled 
7. Embedded browser OAuth Login :enabled 
8. App Secret Proof for Server API calls :enabled 
9. Require 2-factor reauthorization : disabled 
10. Valid OAuth redirect URIs :`http://localhost/dist/include/0auth_provided_by_facebook.php?` (according to the suggesion given in the answer) 
11. Stream post URL security : enabled 

这些是细节。在所有情况下,$user_id = $facebook-> getUser();总是返回0。我该如何解决它?


更多信息.. thhough我不知道它会帮你不要......我正在经历我base_facebook.php,我发现,这是因为 if(signed_request)回到零点永远是假的。

+0

替换现有getCode()功能为什么你有与该网站的DEAUTH回调相同的目标? –

+0

用户是否授权您的应用程序?流量是否发生,仍然得到用户ID 0?那是对的吗?这是你的问题吗? –

+0

是用户授权应用......它在developers.facebook.com角色被提及....和 >还是你的用户ID为0?那是对的吗? 是这就是我的问题 –

回答

0

为了摆脱这个问题,你需要做以下

变化

$login_url = $facebook->getLoginUrl(array(
    'scope'  => 'email,user_location,user_photos,publish_actions,basic_info', 
    'redirect_uri' => 'http://localhost/dist/' 
    )); 

$login_url = $facebook->getLoginUrl(array(
    'scope'  => 'email,user_location,user_photos,publish_actions,basic_info', 
    'redirect_uri' => 'http://localhost/dist/index.php' 
    )); 

休假域名在以下设置的空白。不要给本地主机。COM

App Domains : localhost.com 

然后

Valid OAuth redirect URIs :http://localhost/dist/ 

Valid OAuth redirect URIs :`http://localhost/dist/index.php 

后,现在尝试在那里。

+0

你可以再次检查ITR please..not工作 –

0

变化从应用程序配置您的应用程序的秘密page.then使用上述页面这个新的应用程序秘密你有mentioned.Delete都在浏览器中的Cookie,并尝试加载页面,你会得到正确的响应。

0

对我来说这听起来本地主机的问题,如果你可以使用域来测试你的代码,我在我的网站上运行的一个页面登录系统,我可以给你所有的代码怎么过你的代码看起来不错。

0

编辑base_facebook.php库,并与

protected function getCode() { 
$server_info = array_merge($_GET, $_POST, $_COOKIE); 
    if (isset($server_info['code'])) { 
     if ($this->state !== null && isset($server_info['state']) && $this->state === $server_info['state']) { 
      $this->state = null; 
      $this->clearPersistentData('state'); 
      return $server_info['code']; 
     } else { 
      self::errorLog('CSRF state token does not match one provided.'); 
      return false; 
     } 
    } 
    return false; 
}