1


当我将以下composer包bitgandtter/google-api用于google php api客户端时,因为我将它与laravel 4结合使用,我收到以下错误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 plus 登录按钮登录用户,然后通过$.ajax().

这是我的 api 控制台设置的样子: 在此处输入图像描述

4

2 回答 2

0

我得到了类似的错误。为了解决我的问题,我去了谷歌控制台并重置了密码。我还确保将 Authorized JavaScript origins 设置为正确的地址。

于 2017-03-11T09:43:51.990 回答
-1

http:// localhost :900/auth/google 是目录还是页面?也许如果它是一个目录,最终的 url 是不同的(如 http://localhost:900/auth/google/index.php),谷歌在 2 个字符串之间进行控制,但它们是不同的。

于 2013-10-15T09:03:57.167 回答