我想實現Facebook登錄到我有一個網站。該Web應用程序使用Laravel 4.2構建,我使用的是SammyK/LaravelFacebookSdk
。Facebook通過PHP SDK v4登錄。返回「無效的redirect_uri」
我已經爲這並登錄的初始路徑下面的代碼:對$login_link
做一個die
Route::get('/facebook', function()
{
$login_link = Facebook::getLoginUrl(['email', 'user_status'], 'http://staging.breathe.yogijii.com/facebook/login/');
return Redirect::to($login_link);
});
給了我下面的字符串:
回調路線(臉譜/登錄)爲:
// Endpoint that is redirected to after an authentication attempt
Route::get('/facebook/login', function()
{
/**
* Obtain an access token.
*/
try
{
$token = Facebook::getTokenFromRedirect();
if (! $token)
{
return Redirect::route('login')
->with('flash_notice', 'Unable to obtain access token');
}
}
catch (FacebookQueryBuilderException $e)
{
return Redirect::route('login')->with('flash_notice', $e->getPrevious()->getMessage());
}
if (! $token->isLongLived())
{
/**
* Extend the access token.
*/
try
{
$token = $token->extend();
}
catch (FacebookQueryBuilderException $e)
{
return Redirect::route('login')
->with('flash_notice', $e->getPrevious()->getMessage());
}
}
Facebook::setAccessToken($token);
/**
* Get basic info on the user from Facebook.
*/
try
{
$facebook_user = Facebook::object('me')->fields('id','name')->get();
}
catch (FacebookQueryBuilderException $e)
{
return Redirect::route('login')
->with('flash_notice', $e->getPrevious()->getMessage());
}
// Create the user if not exists or update existing
$user = User::createOrUpdateFacebookObject($facebook_user);
// Log the user into Laravel
Facebook::auth()->login($user);
return Redirect::route('login')
->with('flash_notice', 'Successfully logged in with Facebook');
});
代碼重定向到Facebook和似乎工作正常。然而,當談到回我的應用程序時出現錯誤:
Invalid redirect_uri: Given URL is not allowed by the Application configuration.
我已經看過了一切,在這花了幾個小時。我不確定我是否缺少一些小東西。這是我的應用程序的配置是這樣的:
我的應用程序域完全匹配。我也嘗試製作一個畫布應用程序,也沒有工作。有沒有人有什麼建議?
我試着將我的重定向添加到有效的誓言......仍然無法正常工作。
這將是很好的,你說爲什麼下投票,所以我可以改善這個問題...謝謝 – w3bMak3r
如果您REDIRECT_URI錯了,你應該得到的是錯誤信息甚至在顯示auth對話框之前,但這不會發生。它允許我授權您的應用程序,然後重定向到它。 (然後你的應用說,它無法獲取訪問令牌。)因此,無論出現什麼問題,在這一步似乎都沒有出錯,但之後。 – CBroe
這就是我的想法......奇怪的是它成功重定向後發生的錯誤。你有什麼想法嗎?我一直在看這個好幾個小時。感覺我缺少一些小東西。 – w3bMak3r