JS SDK 与 PHP SDK
从我对各个网站的简要探索来看,JS SDK 似乎比 PHP SDK 更常用。即使是用 PHP 实现的网站也使用 JS SDK。 PHP 参考页面有 776 个赞,而 JS 参考页面有 20k+ 个赞。 PHP 参考页面说 PHP SDK 可以帮助您将 Facebook 登录添加到您的页面,但即使是登录按钮也使用 JS SDK。 PHP SDK 实际上有什么优势吗?为什么 PHP SDK 投入的精力这么少?
From my brief exploration around various websites, it seems that the JS SDK is much more commonly used than the PHP SDK. Even sites that are implemented in PHP use the JS SDK. The PHP reference page has 776 likes, whereas the JS reference page has 20k+ likes. The PHP reference page says the PHP SDK helps you add Facebook Login to your page, but even the Login Button uses the JS SDK. Does the PHP SDK actually have any advantage at all? Why so little effort is being put into the PHP SDK?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么JS SDK势必会更受欢迎。并不是每个人都用 PHP 开发服务器端代码(可以使用 Java/Scala/.NET/Python/etc 等),但每个人都必须用 JavaScript 编写客户端代码。
至于两者的好处,如果可以的话,使用 JavaScript SDK 肯定有好处。
当然,有时您必须在服务器端执行操作,要么是因为您想将结果存储在数据库中,要么是因为这是一项安全敏感操作。 (例如,您永远不会将应用程序 access_token 传递给客户端并从那里使用它作为其秘密)。
另外,PHP SDK 投入的“精力如此之少”,因为它确实非常简单,都是标准的 HTTP 内容,例如发出 GET 请求并返回 Json/XML 响应、从 POST 参数读取signed_request 并对其进行解码。无需任何 SDK 即可轻松完成。 (这就是使用其他服务器端语言的开发人员所做的)。对于 JavaScript SDK 来说则不然,它必须处理跨浏览器问题,必须与 FB 通信来执行诸如滚动画布页面或弹出 Iframe 对话框之类的操作。在没有经过良好测试的 SDK 的情况下尝试这样做,你一定有点疯狂。
Well, the JS SDK is bound to be more popular. Not everyone develops their server side code in PHP, (could be using Java/Scala/.NET/Python/etc etc) but everyone does have to write their client-side code in JavaScript.
As to the benefits of either, there are certainly benefits to using the JavaScript SDK when you can.
There is of course times when you have to do things server side, either because you want to store the result in your database, or its a security sensitive operation. (for example you would never pass your app access_token down to the client and use it from there, as its secret).
Also 'so little effort' is put into the PHP SDK because its really quite simple, its all standard HTTP stuff like making a GET request and getting back a Json/XML response, reading the signed_request from the POST parameters and decoding it. It can be done without any SDK very easily. (And this is what developers using other server-side languages do). The same cannot be said for the JavaScript SDK, which has to deal with cross-browser issues, has to communicate with FB to do things like scroll your canvas page or popup an Iframe dialog. You would have to be a little crazy to attempt to do it without a well test SDK.
PHP SDK 专门是 Facebook API 的服务器端包装器。
如果您运行的是 Node.js,则 JS SDK 可以在服务器中使用,也可以在客户端中使用。
实际上,您可以决定从何处与 Facebook 进行通信:客户端还是服务器端。
The PHP SDK is exclusively a server-side wrapper around Facebook's APIs.
The JS SDK can be used in the server if you're running Node.js, or in the client.
It's really up to you to decide where you'll be communicating with Facebook from: the client-side or the server-side.