PHP SDK - How to make example.php work?

I downloaded the PHP SDK from Github (https://github.com/facebook/facebook-php-sdk) on my server, but cannot get example.php to work:

  • When I open example.php in Safari, I get - you are not connected
  • I click the login link
  • I enter a user and go to Facebook
  • The browser redirects back to my example.php - there is "state" and "code" in the URL
  • example.php still shows that "you are not connected" (this is the essence of my problem)
  • If I add: print $facebook->getAccessToken(); - it prints an Access Token (!!!)

So my question is: what is the problem of example.php? If I have a Facebook access token, why does $facebook->getUser() not return anything?

How to make example.php work so that I can continue to develop my own logic?


PS: at the same time, an example of PHP code here: https://developers.facebook.com/docs/authentication/ works fine, so it looks like I have a problem with php -sdk from Github ... is the Github library stable or rather unfinished, which cannot be used for production?

+4
source share
4 answers

It worked out well ... a few hours after you created the Facebook app, it seems you get pretty weird API results. It seems that example.php is working now without any changes - I really think this is an API server error, cz code definitely works now.

0
source

What version of the PHP SDK have you downloaded. PHP SDK version 2.0 has this problem.

$facebook->getUser() returns nothing.

This is solved in the PHP SDK 3.0. Download version 3 and try with it.

+1
source

In the sample script, basurl parameters are not added when initializing the facebook object. I also spent hours trying to debug the same thing. The js example worked. There after that I added the baseurl in which it worked.

 $facebook = new Facebook(array( 'appId' => '406058216186755', 'secret' => 'adsaqer4sdfsdgfgfg21341324324', 'baseurl' => 'http://ironhide.maanas.co/oauth/facebook.php' )); 
0
source

Are you sure you are using: echo $ facebook-> getUser ()?

I recommend you: http://developers.facebook.com/docs/authentication/

Use PHP SDK v3, v2 is listening!

Good luck.

-one
source

Source: https://habr.com/ru/post/1393373/


All Articles