Facebook php sdk: getUser = 0

I already wrote about getUser returning 0 before, but lately not even my workaround seems to help. No matter what I tried, after giving permissions getUser always returns 0 on the first try. After a long google search that brought no results, I was fed up with this facebook crap and instead, I searched in the Facebook PHP SDK for answers. What I found was a function called getCode in base_facebook.php that seemed to be the source of the problem. And since time is precious, I just edited it:

  protected function getCode() {
    if (!isset($_REQUEST['code']) || !isset($_REQUEST['state'])) {
      return false;
    }
    //return $_REQUEST['code'];
    if ($this->state === $_REQUEST['state']) {
        // CSRF state has done its job, so clear it
        $this->state = null;
        $this->clearPersistentData('state');
        return $_REQUEST['code'];
    }else{
      return $_REQUEST['code'];
    }
    self::errorLog('CSRF state token does not match one provided.');

    return false;
  }

This may be bad style, since I don’t even know what this is supposed to do, but you know what? It works and I’ve had it with Facebook and it’s stupid behaviour.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.