createAuthUrl中添加的queryParams没有返回

问题描述 投票:0回答:1

在 Laravel 应用程序中,我尝试获得在 Google Drive 上保存文件的权限。作为调用 api 的一部分,可以传递应该返回的查询参数。

像这样:

$client = new Client([
            'client_id' => config('services.google-drive.client_id'),
            'client_secret' => config('services.google-drive.client_secret'),
            'scopes' => [
                'https://www.googleapis.com/auth/drive.file',
                'https://www.googleapis.com/auth/drive',
            ],
            'redirect_uri' => route('users.integrations.google-drive.connect'), // NOTE: I do add the parameters here
            'approval_prompt' => 'force',
            'access_type' => 'offline',
        ]);


$authUrl = $client->createAuthUrl($client->getScopes(), ['igd' => $idg]);

$authUrl 是:

https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=offline&client_id=XXXXXXXX&redirect_uri=YYYYYY&state&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&approval_prompt=force&igd=99df36fb-ee4a-4861-8d57-85b0b2905bcd

最后一个参数来自我的应用程序,因此我将其发送给 Google。

批准请求后,“回调”网址如下所示:

https://<my_return_url>?code=4%2F0Adeu5BWppRGhaAsAwDlDxbAMhbFIaEqk1rSHNdMKuQcKe-JXwcTE8fZZmMY3xLSv8XSs7g&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file

缺少“igd”参数。

有什么提示吗?

谢谢。 亲切的问候 斯蒂恩

php google-api google-drive-api google-api-php-client
1个回答
0
投票

您缺少需要用代码交换访问令牌的步骤

// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
$client->setAccessToken($accessToken);

       
© www.soinside.com 2019 - 2024. All rights reserved.