【发布时间】:2014-03-24 22:56:19
【问题描述】:
在我说什么之前,我想说的是,我在 GOOGLE 上搜索了很多,并且找到了很多页面(包括许多这样的问题),其中包含各种解决方案......但我已经一一尝试了它们,但不幸的是没有其中为我工作
我正在尝试使用 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 上面写的代码位于与此文件不同的目录localhost/dist/include/0auth_provided_by_facebook.php 中,我处理所有事情。登录成功和失败时,facebook 会在此处返回值。然后在成功登录时,用户再次被重定向到主页
现在这是我启用、禁用或更改的应用设置的完整列表
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。我该如何解决?
欲了解更多信息..虽然我不知道它对你没有帮助...我正在浏览我的 base_facebook.php,我发现它返回零,因为
if(signed_request)总是错误的。
【问题讨论】:
-
为什么你的 deauth 回调与网站的目标相同?
-
用户是否授权您的应用?流程是否发生并且您仍然获得用户 id 0 ?那是对的吗?这是你的问题吗?
-
是的,用户授权了我的应用程序...在developers.facebook.com 的角色中提到...并且>您仍然获得用户ID 0 吗?那是对的吗?是的,这就是我的问题
标签: php facebook oauth facebook-php-sdk facebook-authentication