【问题标题】:Facebook Authentication: HttpServletResponse.sendRedirect(URL) different to typing the URL directly into browser?Facebook 身份验证:HttpServletResponse.sendRedirect(URL) 与直接在浏览器中输入 URL 不同吗?
【发布时间】:2011-08-09 10:42:07
【问题描述】:

我正在尝试将我的用户重定向到 Facebook 的权限请求页面,方法是将他们重定向到

https://graph.facebook.com/oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&scope={permission_scope}

当我直接在浏览器中输入 URL 时,它会进入正确的页面:出现一个对话框,询问用户是否接受授予我的应用程序的权限。

但是当我通过服务器发送重定向请求时:

response.sendRedirect("https://graph.facebook.com/oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&scope={permission_scope}");

它将用户带入一个带有大 Facebook 徽标的页面。如果用户点击徽标,它将正常显示授权页面。

我想知道我是否在回复中遗漏了一两件事,这使得结果与直接在浏览器中输入不同。有人有同样的问题吗?

【问题讨论】:

  • 他们会阻止 302 重定向吗?我可以看到这种情况,因为中间页面允许用户“将自己重定向”到预期页面。

标签: java facebook servlets facebook-graph-api


【解决方案1】:

这是因为您的应用程序 iFrame(在 apps.facebook.com 上)不能包含来自 Facebook 域的页面。

您需要使用 JavaScript 进行重定向:

response.getWriter().println(
   "<script>" + 
   "top.location.href = \"https://graph.facebook.com/oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&scope={permission_scope}\"" +
   "</script>"
);

【讨论】:

  • 太棒了!非常感谢:)
猜你喜欢
  • 2016-10-24
  • 2020-12-14
  • 2015-09-16
  • 2016-10-02
  • 2012-06-08
  • 2019-03-18
  • 1970-01-01
  • 2022-10-20
  • 2020-10-22
相关资源
最近更新 更多