所以我一直在尝试制作一个网络应用程序,使用https://github.com/kawax/laravel-google-sheets从谷歌工作表中提取数据。 .
我早些时候在工作时设置了这个,效果很好。数据返回没有问题,但是当我尝试将其带回本地服务器上的家庭电脑时,它给了我一个我以前从未见过的错误,并且我正在努力调试。
Google_Service_Exception (400)
{ "error": "invalid_scope", "error_description": "Empty or missing scope not allowed." }
这个问题似乎只在我运行这行代码时出现:
$values = Sheets::sheet('Sheet1')->all();
该区域的完整代码是:
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Sheets;
use Datetime;
use Google;
Use Carbon\Carbon;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function test()
{
Sheets::setService(Google::make('sheets'));
Sheets::spreadsheet('1yYpNNpPPrbraIZeaoQ5v80MobkI9Nv14oLI_S2_RJhY');
$values = Sheets::sheet('Sheet1')->all();
// all() returns array
// Do stuff with data
如有任何帮助,我们将不胜感激。
最佳答案
在你的 config/google.php 添加(完成 php artisanvendor:publish 之后)
'scopes' => [\Google_Service_Sheets::DRIVE, \Google_Service_Sheets::SPREADSHEETS],
然后它应该再次开始工作。
关于Laravel - Google Sheets API 为空或缺少范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48836695/