Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Javascript SDK or PHP SDK for facebook connect in website

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:

  1. I want to record all users that authorize my app in a database (userid's, email addresses) on my server
  2. I want to give users the ability to publish to their walls using the attractive dialogues generated by FB.ui() in the JS SDK
  3. I want to be able to publish a story on a user's wall via my server in response to an external event
  4. 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 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?

like image 821
Casey Flynn Avatar asked Jul 21 '11 04:07

Casey Flynn


People also ask

What is Facebook SDK for JavaScript?

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.

Is JavaScript used in Facebook?

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.

What is Facebook PHP SDK?

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php.


2 Answers

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

like image 67
Relaxing In Cyprus Avatar answered Sep 21 '22 16:09

Relaxing In Cyprus


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:

  1. Because I like javascript more.
  2. 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.

like image 31
squinlan Avatar answered Sep 21 '22 16:09

squinlan