phpfacebookcodeigniterfacebook-graph-apifacebook-php-sdk

How do I encode or decode my url when redireted back to my site from Facebook with once we FbConnect


its been I while since I try to solve that problem, I've already asked it here, but didn't get any response, I've been googleling my problem in every sense but I just can't make it. I just need to know how could I get a valid url when I send to FaceBook my url I want FaceBook to redirect my user back : site_url(‘main/verification’) (I'm working with codeIgniter)

so my loginUrl looks like this :

https://www.facebook.com/dialog/oauth?client_id=248650435198175.&.redirect_uri=http%.3A%.2F%.2Flocalhost%.2FSocialCart%.2Findex.php%.3F%.2Fmain%.2Fverification&state=004dc1ebe9e081b2222408434af7dbd5&scope=email

(DELETE ALL POINTS AFTER ALL THE %)

once I click on the link, I’m directed to FaceBook, but then, I’m redirected to my main page (and not main/verification) with that URL in my browser :

http://localhost/SocialCart/index.php?%.2.Fmain%.2.Fverification&state=0e3ae6ca3e7869f618d65ad&code=AQCwwZUevy-SfeNLgUC55Rg0bi7noi_oczwt_2TmR-DobC8xc6STYIW82VLi23fzf9d-J5tdufdOLpc#_=_

Well I’ve deleted a part of that long code but you see that I get, after my index.php? an %.2.F instead of an / and the & should be ? (I think)

(remove the points ‘.’ between every %2 and 2F)

How could I fix it please ? WHY is my redirectUrl only partially decoded by my browser ? it seems to decode until the index.php and then, it stops replacing all the '%.2F' by '/' (once again no point after the %) I guess I’m gonna need the url rewriting or urlencode() functions but the fact is that only half of the url is well interpreted, and not the rest. I really don't now what to do ..

I guess I have to check into the getLoginUrl() function, its the function which is in charge of retrieving the part of the login url that redirect the user from fb to my websiteif the url is well encoded but I've tried everything and nothing seems to work.

Here is the function (that you can find in any base_facebook.php of the php API graph.) :

  /**
   * Get a Login URL for use with redirects. By default, full page redirect is
   * assumed. If you are using the generated URL with a window.open() call in
   * JavaScript, you can pass in display=popup as part of the $params.
   *
   * The parameters:
   * - redirect_uri: the url to go to after a successful login
   * - scope: comma separated list of requested extended perms
   *
   * @param array $params Provide custom parameters
   * @return string The URL for the login flow
   */
  public function getLoginUrl($params=array()) {
    $this->establishCSRFTokenState();
    $currentUrl = $this->getCurrentUrl();

    // if 'scope' is passed as an array, convert to comma separated list
    $scopeParams = isset($params['scope']) ? $params['scope'] : null;
    if ($scopeParams && is_array($scopeParams)) {
      $params['scope'] = implode(',', $scopeParams);
    }

    return $this->getUrl(
      'www',
      'dialog/oauth',
      array_merge(array(
                    'client_id' => $this->getAppId(),
                    'redirect_uri' => site_url(), // possibly overwritten
                    'state' => $this->state),
                  $params));
  }

Thank you


Solution

  • Don't make any changes in base_facebook.php Use following code:

    $params = array(
      'scope' => 'read_stream, friends_likes',
      'redirect_uri' => site_url(‘main/verification’)
    );
    
    $loginUrl = $facebook->getLoginUrl($params);