Facebook的连接API回调URL [英] facebook connect api callback url

查看:361
本文介绍了Facebook的连接API回调URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网站,我使用PHP SDK 3放置了facebook连接。

I'm develpping a site and I put the facebook connect using PHP SDK 3.

问题是在用户验证身份后,facebook返回页面的结果并授予权限。对我来说,用户单击允许后,它将进行身份验证,然后使用查询字符串返回到同一页面(索引)。

The problem is that the page where facebook returns the results after the user authenticates and grants permission. for me after a user clicks "allow", it authenticates and then returns back to the same page (index) with a query string.

我想要的是用户单击不允许,他将被重定向到某个页面,例如login-fail.php,并且如果他授予许可,他将被重定向到login-success.php,将在其中处理他的数据并将其存储在数据库中。

What I want is that if the user clicks "don't allow", he will be redirected to a certain page like login-fail.php, and if he grants permission he is redirected to login-success.php where his data will be processed and stored in the database.

有什么想法吗?

推荐答案

您不能在错误的情况。最好的办法是设置一个重定向URL,无论成功或失败,该重定向URL都是相同的:

You cannot specify a redirect URL in case of error. The best you can do is to set a redirect URL that will be the same for success or error :

$args['redirect_uri'] = "http://www.yoursite.com/after-dialog.php"
$url = $facebook->getLoginUrl($args);

如果用户单击不允许,他将被重定向到页面 after-dialog.php 具有以下GET参数:

If the user clicks "Don't allow", he will be redirected to the page after-dialog.php with the following GET parameters :

error = access_denied
error_reason = user_denied
error_description = The+user+denied+your+request.

如果您真的想根据登录成功重定向他,则可以在顶部进行跟踪 after-dialog.php 文件的来源:

If you really want to redirect him according the success of his login, you can track it at the top of the after-dialog.php file by :

if (isset($_GET['error'])) {
  header('Location: http://www.yoursite.com/login-failed.php");
} else {
  header('Location: http://www.yoursite.com/login-success.php");
}

希望有帮助!

编辑:正如您指出(在此答案的注释中),SDK代码中的注释说:

As you pointed out (in the comments of this answer) the comments in the code of the SDK say :

redirect_uri: the url to go to after a successful login

但是 API的引用说:


如果用户按不允许,则您的应用未获得授权。 OAuth对话框会将用户浏览器重定向(通过HTTP 302)到您在 redirect_uri 参数中传递的URL。

If the user presses Don't Allow, your app is not authorized. The OAuth Dialog will redirect (via HTTP 302) the user's browser to the URL you passed in the redirect_uri parameter.

和:


如果用户按下 Allow ,则您的应用已获得授权。 OAuth对话框会将用户浏览器重定向(通过HTTP 302)到您在 redirect_uri 参数中传递的URL。

If the user presses Allow, your app is authorized. The OAuth Dialog will redirect (via HTTP 302) the user's browser to the URL you passed in the redirect_uri parameter.

我还运行了一些测试,即使用户单击不允许,用户也始终重定向到 redirect_uri 。它必须是代码注释中的错字。

I also ran some tests and the user is always redirect to redirect_uri, even if he clicks "Don't allow". It must be a typo in the code comments.

这篇关于Facebook的连接API回调URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆