0

I’m a junior developer and I’m working on a website tying to integrate a Facebook login using the JavaScript SDK and PHP SDK that Facebook provides in Facebook developers . I was able to set up JavaScript SDK and uploaded the files for PHP SDK to my server for testing.

This is what I have so far: http://www.reyesmotion.com/kno_login/index.html

What I have works as after clicking “Log In” button I’m prompted to enter credentials to log in with Facebook or automatically logs me in if I’m already logged in on Facebook.

However, I need to be able to keep cookie and reuse it for various applications on the site I’m working on.

One of the steps for setting up PHP SDK is as fallow:

Use the SDK by instantiating a new Facebook object with, at a minimum, your App ID and App Secret:

require_once("facebook.php");
$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';

$facebook = new Facebook($config);

Here is the link for instructions from FB: https://developers.facebook.com/docs/reference/php/

Where and how do I initialize “Facebook object”, what file should contain this code? The instructions aren’t very clear to me.
If anyone can guide me on the right direction I would really appreciated.

irm
  • 4,073
  • 6
  • 28
  • 32
  • Are you using mvc architecture or just single php files where you have a php file for each page? – Fabio Antunes Jul 31 '13 at 00:55
  • We will be using mvc. – irm Jul 31 '13 at 00:57
  • Well since you'll be loading every time a page is requested I advise you to create a private method, responsible for loading the library and instantiating the facebook object. By the way, are you planning using any framework, or just code everything? – Fabio Antunes Jul 31 '13 at 01:04
  • We will be using Symfony – irm Jul 31 '13 at 01:09
  • As of now I'm just trying to get the php part working though. Should I just include the code in my main php or html file? How can I test? I have little experience wit php and I just need to pass this project to the other developers. – irm Jul 31 '13 at 01:16
  • well then you should use the symfony services, that allows you to create a class that can be loaded by any controller, you can read more about that on the accepted answer on this question http://stackoverflow.com/questions/10336401/symfony2-global-functions if you just want to test it very quickly just just load the php sdk on your controller and instantiate the facebook object – Fabio Antunes Jul 31 '13 at 01:20

1 Answers1

0

I write it for reference:

The Facebook object consents to do operations like check if a determinate user is logged in or to log out users and so on.

It incapsulates HTTP requests to Facebook Graph servers.

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

So the object should be obviously instantiate before you use its methods, like get(), post(), delete()

It's convenient to instantiate it at the beginning of your PHP site, for example in the index/home page and store it globally (you can also just instantiate it everytime is needed).

$GLOBALS['fb'] = new \Facebook\Facebook([
      'app_id' => '',
      'app_secret' => '',
      'default_graph_version' => '',
    ]);

Don't forget to include the autoload before:

include('Facebook/autoload.php');