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:
- I want to record all users that authorize my app in a database (userid's, email addresses) on my server
- I want to give users the ability to publish to their walls using the attractive dialogues generated by FB.ui() in the JS SDK
- I want to be able to publish a story on a user's wall via my server in response to an external event
- I want to enable/disable certain functionality on my website based on whether or not the user is currently logged into facebook
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 o开发者_开发百科f 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 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:
- Because I like javascript more.
- Because users can interact with your site while its logging in to Facebook and communicating with your server.
If you only want to use one, then your number 3 pretty much requires the PHP SDK. Beyond that, it really is personal preference.
精彩评论