0

This is my code:

$loginUrl = $facebook->getLoginUrl(array( 'scope' => 'publish_actions', 'redirect_uri' => 'http://mysite.com/', )); 

It works but if I remove redirect_uri it doesn't work anymore.

$loginUrl = $facebook->getLoginUrl(array( 'scope' => 'publish_actions' )); 

According to Facebook domcumentation redirect_uri is optional. https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/

Im trying to redirect the users to the same url they were on before logging in.

Update: This problem occurs when the url is mysite.com/post23 but when url is mysite.com/staticpage or mysite.com there are no problems

Any workarounds?

EDIT: It looks like a bug, it doesn't work with certain url in the same site

I wil try and report it to Facebook.

2
  • weird, it works for me. which version of php-sdk you are using ? Commented Oct 13, 2012 at 17:53
  • I'm using Facebook PHP SDK (v.3.2.0) from github.com/facebook/facebook-php-sdk Commented Oct 13, 2012 at 18:05

2 Answers 2

2

it should redirect to current url if redirect_uri param not given. check if your getLoginUrl function in base_facebook.php looks like:

public function getLoginUrl($params=array()) { $this->establishCSRFTokenState(); $currentUrl = explode("?",$this->getCurrentUrl()); $currentUrl = $currentUrl[0]; // 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' => $currentUrl, // possibly overwritten 'state' => $this->state), $params)); } 
Sign up to request clarification or add additional context in comments.

1 Comment

It didn't look exactly like that, I edited the file and then tried again with the same results.
0

I fixed this strange problem like this:

Include this line at the top of your files when user is not logged in:

$_SESSION['redir_after_auth'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 

then check if user is trying to login and that session is set

if (isset($_GET['action']) AND $_GET['action']=="fblogin" && isset($_SESSION['redir_after_auth'])) { header('Location: ' . $_SESSION['redir_after_auth']); } $loginUrl = $facebook->getLoginUrl(array( 'scope' => 'publish_actions', 'redirect_uri' => 'mysite.com/?action=fblogin' )); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.