我要拔头发了!帮助 !!
更新:我正在使用 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']
});
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 https://github.com/axios/axios了解有关有效请求的更多信息
选项。在 Object.validate (/user_code/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) 处完成 (/user_code/node_modules/google-auth-library/build/ src/auth/oauth2client.js:29:58) 在 process._tickDomainCallback (内部/process/next_tick.js:135:7)
我通过以下方式解决了这个问题https://www.npmjs.com/package/googleapis https://www.npmjs.com/package/googleapis并且不使用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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)