是否可以使用ajax从canvas教程中检索facebook应用程序授权代码?
这是画布教程中的代码 http://developers.facebook.com/docs/appsonfacebook/tutorial/
这得到授权代码,将用户重定向回画布页面并在 url 中显示代码。
类似于 http://apps.facebook.com/yourapp/?code=1234thecode5678
那么,是否可以使用ajax 来实现并获取代码而无需重定向?而不是这个方法?
提前致谢
$app_id = "YOUR_APP_ID";
$canvas_page = "YOUR_CANVAS_PAGE_URL";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
This is the code from the canvas tutorial
http://developers.facebook.com/docs/appsonfacebook/tutorial/
This gets the authorization code, redirects the user back to the canvas page and displays the code in the url.
Something like, http://apps.facebook.com/yourapp/?code=1234thecode5678
So, is it possible to do it using ajax and get the code without redirecting? Instead of this method?
Thanks in advance
$app_id = "YOUR_APP_ID";
$canvas_page = "YOUR_CANVAS_PAGE_URL";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Facebook JS SDK 让用户登录,而无需刷新或重定向用户。
摘自 Facebook JS SDK 文档 主题下的 FB.login
注意:如果您使用的是 oAuth 2.0,这是实现(你确实应该如此)。取自同一网址:
You can use the Facebook JS SDK to log the user in with out having to refresh or redirect the user.
Taken from the Facebook JS SDK Documentation under the topic FB.login
Note : This is the implementation if you are using oAuth 2.0 (and you really should be). Taken from the same url :