Facebook PHP SDK - getUser() suddenly returns 0

前端 未结 4 1544
Happy的楠姐
Happy的楠姐 2021-01-12 06:31

First of all, to get this out of the way, I\'ve spent hours looking through answers to this question here on StackOverflow, and tried to solve it on my own, but it just isn\

相关标签:
4条回答
  • 2021-01-12 06:38

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

    0 讨论(0)
  • 2021-01-12 06:49

    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!

    0 讨论(0)
  • 2021-01-12 06:53

    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

    0 讨论(0)
  • 2021-01-12 06:55

    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!

    0 讨论(0)
提交回复
热议问题