2016-07-22 73 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

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

相關問題