bitgandtter/google-api
laravel 4と組み合わせて使用しているため、Google php APIクライアントに
次のcomposerパッケージを使用すると、次のエラーが発生しますredirect_uri_mismatch
。私のコードは次のようになります(これはapp/lib
、PSR-0 仕様の使用の下にあります):
class Google {
private $client;
private $token;
public function __construct($code)
{
$this->client = new Google_Client();
$this->client->setApplicationName("camelCaseD");
$this->client->setClientId('SOMENUMBERS.apps.googleusercontent.com');
$this->client->setClientSecret('PRECIOUS');
$this->client->setRedirectUri('http://localhost:9000/auth/google');
$this->client->authenticate($code);
}
}
私のルートは次のとおりです。
Route::group(['prefix' => 'auth'], function()
{
Route::post('google', function()
{
$postInput = file_get_contents('php://input');
try
{
$google = new Google($postInput);
} catch (Exception $e)
{
return Redirect::to('signin')->with('error', $e->getMessage());
}
});
});
公式のGoogleプラスサインインボタンを使用してユーザーをログインさせ、認証コードを経由してサーバーに渡しています$.ajax()
。
私のAPIコンソール設定は次のようになります。