通过Java访问Facebook Cookie数据(无需php-sdk)
我正在使用服务器端流程进行 FB 身份验证(如 http://developers.facebook.com/ 中所述docs/authentication/),我能够成功获取身份验证令牌。现在我想实现这一点 - 1)服务器端能够识别用户 2)当用户退出 FB 时,我的服务器代码能够在下一个请求来自客户端时检测到这一点。
我能想到的唯一方法是将 Auth 令牌保存为用户端的 cookie,将令牌与服务器上的 userID 相关联,然后通过 FB JavaScript SDK 在 OnLogout 事件处理程序中删除 cookie。我想知道是否有更好的(推荐的?)方法来做到这一点。特别是,我想使用 FB cookies(FB.init 创建的 cookies)来执行此操作。该 cookie 对我来说似乎是加密的,除了 在哪里可以找到 Facebook cookie?。我记得读过一些 PHP SDK 函数,它可以解密 cookie (GetUser),但我无法使用它,因为我的代码是 Java 语言。如果可能的话,我想避免使用第三方 Facebook Java SDK。如果有任何关于此事的指示,我将不胜感激。
I am using the server side flow for FB authentication (as mentioned on http://developers.facebook.com/docs/authentication/) and I am able to get the authentication token successfully. Now I want to implement this - 1) The server side is able to identify the user 2) When the user logs out of FB, my server code is able to detect this when the next request comes from the client.
The only way I could think of doing this was to save the Auth token as a cookie on the users end, associate the token with the userID on the server, and delete the cookie in the OnLogout event handler through the FB JavaScript SDK. I wanted to know if there is a better (recommended?) way for doing this. In particular, I wanted to use the FB cookies (cookies which FB.init creates) to do this. That cookie appears encrypted to me, and I can't find any documentation about decrypting it apart from Where to find the Facebook cookie?. I remember reading about some PHP SDK function which decrypts the cookie (GetUser) but I can't use that since my code is in Java. If possible, I'd want to avoid using 3rd party Facebook Java SDKs. I'd be grateful for any pointers about this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要避免使用已经为您完成所有这些工作的 Java API?!
无论如何,请查看任何现有的 Java/FB API——如果您无法将 PHP 转换为 Java,不妨使用已经存在的代码重新发明轮子。
http://restfb.com/
如果我要解决这个问题,我会采用一个已知可以工作的 API (就像 Koala for Rails 一样)并向后工作。不过,请务必选择一个实现强制 OAuth 2 内容的工具。
Why do you want to avoid using a Java API that has already done all of this work for you?!
In any case, take a look at any of the existing Java/FB APIs--if you're unable to translate PHP to Java, might as well reinvent the wheel using code that already exists.
http://restfb.com/
If I were going about this I'd take an API that is known to work (like Koala for Rails) and work backwards. Make sure to pick one that implements the mandatory OAuth 2 stuff, though.