问题描述
我正在拔头发!救命 !!更新:我使用google-auth-library的v1.0.0和googleapis的v24.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']
});
返回新的承诺(函数(解决,拒绝){
client.authorize()
.then((obj)=> {
//在此次通话中失败
sheets.spreadsheets.values.append({
auth:client
,范围:A1
,spreadsheetId :SHEET_ID
,insertDataOptions:INSERT_ROWS
,responseDateTimeRenderOption:FORMATTED_STRING
,responseValueRenderOption:UNFORMATTED_VALUE
,valueInputOption:RAW
,resource:{
值:[
[1,2,3]
]
}
.......为清晰起见省略了代码
我一直得到:
'json'不是有效的配置选项。请改用'data'。此库正在使用Axios请求。请参阅
以了解有关有效请求
选项的更多信息。在Object.validate(/ user_co) de / node_modules / google-auth-
library / build / src / options.js:32:19)在DefaultTransporter.request(/user_code/node_modules/google-auth-library/build/src/transporters.js: 49:23)在JWT。 (/user_code/node_modules/google-auth-library/build/src/auth/oauth2client.js:427:63)步骤(/user_code/node_modules/google-auth-library/build/src/auth/oauth2client.js: 57:23)在Object.next(/user_code/node_modules/google-auth-library/build/src/auth/oauth2client.js:38:53)at fulfilled(/ user_code / node_modules / google-auth-library / build / src / auth / oauth2client.js:29:58)at process._tickDomainCallback(internal / process / next_tick.js:135:7)
我按照 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
);
返回新的承诺((解决,拒绝)=> {
client.authorize((错误,令牌)=> {
如果(错误){
拒绝(错误) );
} else {
google.options({
auth:client
});
resolve();
}
} );
});
//然后按原样使用客户
I am pulling my hair out ! Help !!UPDATE: I am using v1.0.0 of google-auth-library and v24.0.0 of googleapis.
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]
]
}
....... code omitted for clarity
I keep getting:
'json' is not a valid configuration option. Please use 'data' instead. This library is using Axios for requests. Please seehttps://github.com/axios/axios to learn more about the valid requestoptions. at Object.validate (/user_code/node_modules/google-auth-library/build/src/options.js:32:19) at DefaultTransporter.request (/user_code/node_modules/google-auth-library/build/src/transporters.js:49:23) at JWT. (/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 fulfilled (/user_code/node_modules/google-auth-library/build/src/auth/oauth2client.js:29:58) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
I solved it by following https://www.npmjs.com/package/googleapis and not using google-auth-library
at all.
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 did
这篇关于Google表格,带有服务帐户的JWT客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!