2016-07-22 71 views
7

我使用的的NodeJS下面的脚本制作一个脚本来读取从谷歌电子表格数据:谷歌电子表格的API请求了验证范围不足

var url = oauth2Client.generateAuthUrl({ 
    access_type:  'offline', 
    approval_prompt: 'force', 
    scope: [ 
     'https://www.googleapis.com/auth/analytics.readonly', 
     'https://www.googleapis.com/auth/drive', 
     'https://www.googleapis.com/auth/spreadsheets' 
    ] 
}); 
global.googleapis = { expiry_date: 0 }; 
google.options({ auth: oauth2Client }); 
var sheets = google.sheets('v4'); 
sheets.spreadsheets.get({ spreadsheetId: 'id'}, function(err, data) { 
    res.send(err, data); 
}); 

但在每一个get请求我得到这个错误:

Request had insufficient authentication scopes. 

我检查了Google开发者控制台以启用Google Drive API并启用了它,所以我不知道它会是什么。

回答

4

首先,请确保您的在您的Developers Console中启用Sheets API

insufficient authentication scopes是OAuth 2.0令牌中的错误,该请求中指定的请求指定scopes不足以访问请求的数据。

因此,请确保您使用正确的和所有必要的范围,并检查此Authorizing requests with OAuth 2.0如果您正确地按照这里的步骤。

最后,尝试撤销访问并尝试重做它。

欲了解更多信息,请查看此相关的SO问题:

15

的范围不好看,也许你应该尝试删除以前存储的凭据在/Users/yourUserName/.credentials/sheets.googleapis.com-projectName/*,然后再次执行该应用程序以获取新凭据。

+1

此解决方案的工作原理! –

相关问题