This is driving me crazy >=(
$facebook->getUser() works well sometimes, but sometimes returns 0
Here is my code:
require \'fbapi/facebook.php\';
$
So i was struggling with the same problem, getUser() always returned 0. Did not make any sense at all. NginX error logs was showing the following error 'CSRF state token does not match one provided'. Then I started debugging the sdk and narrowed it down to getAccessTokenFromCode() not able to get the right accesstoken from the Facebook servers, something to do with SSL certificates.
The solution at the below mentioned link solved the problem for me.
https://github.com/facebook/php-sdk/issues/272
Also you may need to copy the 'fb_ca_chain_bundle.crt' file bundled with the sdk to folder where your facebook class file is located. i did.
I hope this makes sense.