1


bitgandtter/google-apilaravel 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コンソール設定は次のようになります。 ここに画像の説明を入力

4

2 に答える 2

0

同様のエラーが発生しました。私の問題を解決するために、Google コンソールにアクセスしてシークレットをリセットしました。また、Authorized JavaScript origins が正しいアドレスに設定されていることも確認しました。

于 2017-03-11T09:43:51.990 に答える