Facebook PHP SDK - getUser() suddenly returns 0

馋奶兔 提交于 2019-12-01 03:51:18

In base_facebook.php add the following 2 lines under $CURL_OPTS:

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2

Which makes it...

public static $CURL_OPTS = array(
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_USERAGENT      => 'facebook-php-3.2',
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => 2
  );

I'm not sure how much of a security issue this is, but it makes the Login with Facebook work, so there you have it.

EDIT: New SDK released which fixes this problem: https://github.com/facebook/facebook-php-sdk

I think you need to setAccessToken() before calling any facebook methods, even when the use has authorized your app and is logged in.

I had the same problem. It turned out i was using localhost. Though the allow access dialog appeared on facebook and i was redirected back to my web page, getUser still returned zero.

My Solution

Once i uploaded my code and tested it online, reasonable facebook errors appeared then had to change my "App Domains" and "Site Url" to relevant values for my online test website NOT localhost. And then it worked!

I had this issue, which turned out to be a corrupt certificate. I think I had autocrlf turned on in Git. I don't know if that fixed it or not, but blowing away my whole repo and re-cloning from source caused this problem to clear right up!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!