授权后,Facebook 重定向到我的网站,但未设置 userID
用户访问我的应用程序的画布页面,该页面指示他们授权该应用程序。然后,它将它们重定向到我的网站,我在其中使用 PHP SDK 查找有关用户的信息。
不幸的是,从 Facebook 重定向后,userID 返回 0。
$fb_user = $facebook->getUser();
这仅在授权后立即发生。如果用户导航到我网站上的另一个页面,或重新加载页面,则会返回正确的 UID,并且一切都会按预期运行。
重定向是否可以在 Facebook 完成授权之前发生? Facebook 是否在重定向中发送用户 ID? (可以配置吗?)
A user visits my application's canvas page which directs them to authorize the application. It then redirects them to my website where I use the PHP SDK to look up information about the user.
Unfortunately the userID is returning 0 after the redirect from Facebook.
$fb_user = $facebook->getUser();
This ONLY happens immediately after authorization. If the user navigates to another page on my site, or reloads the page, the correct UID is returned and everything works as expected.
Could the redirect happen before Facebook completes the authorization? Does Facebook send the userID in the redirect? (Can that be configured?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此问题的解决方法:
在我的画布页面上,我访问 request_ids 并将它们附加到授权请求的 url 的查询字符串中。授权会将 request_ids 参数转发到我的网站。
“授权”链接上的 JavaScript:
然后,在我的网站上,我检查 Faecbook user_id。如果为 0,我会查找 request_id 参数。如果存在,我会对图表进行 api 调用以获取关联的 user_id。我使用 user_id 而不是 调用 /me:
对 /me 的调用不会返回任何内容,因为 Facebook 没有返回登录用户。 (错误。)
这有点简单,但你明白了......
Work-around for this issue:
On my canvas page, I access the request_ids and append them to the query string of the url for the authorization request. The authorization will forward the request_ids parameter on to my website.
Javascript on an "authorize" link:
Then, on my website, I check for the Faecbook user_id. If that is 0, I look for the request_id parameter. If there, I make an api call to the graph to get the associated user_id. I use the user_id INSTEAD OF calling /me:
A call to /me returns nothing since Facebook isn't returning a logged-in user. (The bug.)
This is boiled down a little bit, but you get the idea...
我们得到这个,授权回调后的第一页要么不提供用户,不提供权限,要么两者兼而有之。应该被记录为错误
We get this, the first page after the authorisation callback either gives no user, no perms or both. Should be logged as a bug
Adam 的解决方法效果很好,但由于某些原因它并不完全适合我。我的解决方案是从JS授权中获取所有必需的用户数据并将其写入php会话中。希望,它会对某人有所帮助。
JS 验证函数:
Action.php
Adam's workaround works great, but due to some reasons it didn't fully suit me. My solution was to get all required user data from JS authorization and write it into php session. Hope, it will help someone.
JS auth function:
Action.php