我要把头发拔出来!救命!!更新:我使用的是googleapis库的1.0.0版本和谷歌的24.0.0版本。
const { JWT } = require('google-auth-library');
var google = require('googleapis');
var sheets = google.sheets('v4');
const client = new JWT({
email: keys.client_email
,key: keys.private_key
,scopes: ['https://spreadsheets.google.com/feeds']
});
return new Promise(function(resolve, reject) {
client.authorize()
.then((obj) => {
// fails at this call
sheets.spreadsheets.values.append({
auth: client
,range: "A1"
,spreadsheetId: SHEET_ID
,insertDataOptions: "INSERT_ROWS"
,responseDateTimeRenderOption: "FORMATTED_STRING"
,responseValueRenderOption: "UNFORMATTED_VALUE"
,valueInputOption: "RAW"
,resource: {
values: [
[1,2,3]
]
}.为清晰起见省略的代码
我一直得到:
‘'json’不是一个有效的配置选项。请用“数据”代替。这个库对请求使用Axios。请参阅https://github.com/axios/axios了解有关有效请求选项的更多信息。在JWT的(/user_code/node_modules/google-auth-library/build/src/transporters.js:49:23) Object.validate (/user_code/node_Object.validate/google-auth库/Object.validate/src/options.js:32:19)。(/user_code/node_modules/google-auth-library/build/src/auth/oauth2client.js:427:63) at step (/user_code/node_modules/google-auth-library/build/src/auth/oauth2client.js:57:23) at Object.next (/user_code/node_modules/google-auth-library/build/src/auth/oauth2client.js:38:53) at Object.next (/user_code/node_modules/google-auth-library/build/src/auth/( oauth2client.js:29:58) at process._tickDomainCallback (process._tickDomainCallback/process/next_tick.js:135:7)
发布于 2018-01-16 21:32:37
我通过跟踪https://www.npmjs.com/package/googleapis而根本不使用google-auth-library来解决这个问题。
var google = require('googleapis');
const client = new google.auth.JWT(
keys.client_email,
null,
keys.private_key,
['https://www.googleapis.com/auth/spreadsheets'],
null
);
return new Promise((resolve, reject) => {
client.authorize((err, tokens) => {
if (err) {
reject(err);
} else {
google.options({
auth: client
});
resolve();
}
});
});
//and then use client as you didhttps://stackoverflow.com/questions/48242812
复制相似问题