Using Facebook APIs Graph API PHP

I use the PHP library for the Graph API ( http://github.com/facebook/php-sdk ), but I'm a bit confused about how everything works (or not).

I just want to authenticate the user and return the user id. What I really want to know is what you need to do when a user logs into Facebook and returns to my site. The url has data called a "session". Does it need to be stored in order to constantly receive a user ID? This is really not obvious to me, from the samples or (lack of) documentation.

In addition, it would be easier to just cut out the PHP library as a whole and simply process the response itself, storing it in a session variable. If I did this, what is the best way to get / retrieve the current user id?

Edit:

Currently, I copied the facebook.php file and the example.php file from GitHub and only changed the name and secret name of the application in example.php. It does not store a cookie and says, "You are not connected." However, when I print_r($session);work (but only if the url contains session data).

Has anyone else experienced such problems? Is it possible that running on localhost causes this?

Edit:

I uploaded the exact same two files to the host and it worked perfectly. He saved the cookie and showed all the necessary information. Most likely, running on the local host causes problems. I changed the settings on the Connect tab in the Facebook developer app, but still no luck.

Does anyone know how to do this from localhost or what am I doing wrong?

+5
source share
5 answers

The url has data called a "session". Does it need to be stored in order to constantly receive a user ID?

Yes, it needs to be saved, but the Facebook class parses it and stores it in a cookie for you.


, PHP , .

Facebook, facebook.php, API, , , URL-, ( URL-, cookie), ( JSON "" ) PHP ..

, , , PHP, .

, ($uid), getUser:

if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}

$uid - , $me - ( , ). , :

$me = $facebook->api('/' . $uid); //Generates https://graph.facebook.com/[uid]

, , , curl Facebook (makeRequest) - NO-. , $me , , : " ". $uid, , .

+5

setCookieFromSession ($ session = null)

, $domain emtpy. :

if ($domain != '') {
    setcookie($cookieName, $value, $expires, '/', '.' . $domain);
} else {
    setcookie($cookieName, $value, $expires, '/');
}
+1

facebook.php github? , , .

0

, - Facebook (), .

I found that you need to make a call / oauth / authorize (with request parameters) to authorize the website / application so that Facebook provides you with an access token.

0
source

I think you can use this http://3aroundweb.in/facebook-connect-using-graph-api/ It contains a practical guide and working code to download :)

-1
source

All Articles