I'm building a website that will authenticate users via Facebook connect and I'm torn between using the PHP SDK/Server-side flow or the JS SDK/Client-side flow.
Here are some considerations:
There are prob a few more I can think of. But based on these requirements I'm guessing I'm going to need to use both SDKs. But which SDK should I rely on for the initial application authorization/new user recording in my database?
My idea of how this might work in both scenarios:
JS SDK:
User selects login button, callback method fires AJAX request to server and passes along the authenticated user's FBID via post. Code on server determines if this is a new user, and records in database if no existing record is found + records access_token to allow server-side API requests.
PHP SDK:
User is redirected to Facebook's authorize page and script that is executed after Facebook redirects a user back to my app records a new record if no existing record for that user is found. But will the JS SDK be able to execute calls to the API if I've authenticated using the server-side flow?
The Facebook SDK for JavaScript provides a rich set of client-side functionality that: Enables you to use the Like Button and other Social Plugins on your site. Enables you to use Facebook Login to lower the barrier for people to sign up on your site. Makes it easy to call into Facebook's Graph API.
Facebook only uses one language in the Front-end that is JavaScript. JavaScript is the most popular programming language today as it is used by almost every platform in the front-end development that you visit today.
The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php.
The latest (3.11) build of the PHP SDK includes an example of how you can use both the PHP SDK and the Javascript SDK together. To summarise, they communicate via a cookie.
This answer is probably a bit late for you, but I thought I would mention it in case anybody else is looking.
https://github.com/facebook/php-sdk
You've already got a strong analysis of the differences between the languages. Beyond that its really a preference and its true there is nothing holding you from using both.
To answer your question though it would, in my opinion, best to use javascript:
If you only want to use one, then your number 3 pretty much requires the PHP SDK. Beyond that, it really is personal preference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With