【问题标题】:Refresh token must be passed in or set as part of setAccessToken刷新令牌必须传入或设置为 setAccessToken 的一部分
【发布时间】:2021-08-02 19:20:54
【问题描述】:

令牌传输发生错误。 Laravel,Google Drive API

提供者代码

class GoogleDriveServiceProvider extends ServiceProvider
{

    public function register()
    {
        //
    }
    
    public function boot()
    {
        Storage::extend('google', function($app, $config) {
            $client = new \Google_Client();
            $client->setClientId($config['clientId']);
            $client->setClientSecret($config['clientSecret']);
            $client->refreshToken($config['refreshToken']);
            $client->setAccessType('offline');
            $client->setApprovalPrompt('force');

            $service = new \Google_Service_Drive($client);
            $adapter = new GoogleDriveAdapter($service, $config['folderId']);

            return new Filesystem($adapter);
        });
    }
}

错误

上传项目到Heroku时出现这个错误

{ "message": "刷新令牌必须传入或设置为 setAccessToken 的一部分" “异常”:“登录异常”, ... }

请告诉我如何解决这个问题,提前谢谢。

【问题讨论】:

标签: laravel api


【解决方案1】:

阅读您的代码,我想您已按照本教程进行操作:

“使用 Google Drive API 设置 Laravel Storage 驱动程序”

https://gist.github.com/sergomet/f234cc7a8351352170eb547cccd65011

我遇到了类似的问题。在尝试了多种解决方案后,我遵循了本教程:

https://robindirksen.com/blog/google-drive-storage-as-filesystem-in-laravel

并将 GoogleDriveServiceProvider 替换为:

<?php

namespace App\Providers;

use Google_Client;
use Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
use Storage;

class GoogleDriveServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
 *
 * @return void
 */
public function boot()
{
    Storage::extend('google', function($app, $config) {
        $client = new Google_Client();
        $client->setClientId($config['clientId']);
        $client->setClientSecret($config['clientSecret']);
        $client->refreshToken($config['refreshToken']);
        $service = new \Google_Service_Drive($client);

        $options = [];
        if(isset($config['teamDriveId'])) {
            $options['teamDriveId'] = $config['teamDriveId'];
        }

        $adapter = new GoogleDriveAdapter($service, $config['folderId'], $options);

        return new Filesystem($adapter);
    });
}

/**
 * Register the application services.
 *
 * @return void
 */
public function register()
{
    //
}
}

【讨论】:

    猜你喜欢
    • 2017-01-11
    • 2019-02-23
    • 2018-02-24
    • 1970-01-01
    • 2019-07-01
    • 2019-10-21
    • 2022-06-18
    • 2020-03-23
    • 2021-11-07
    相关资源
    最近更新 更多