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?
问题:
回答1:
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.
- Less load on your server.
- Better response time as the request goes straight from the clients browser to Facebook, rather than from their browser => your server => Facebook, and back again.
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.
回答2:
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.