我有以下“node-rest-client”npm包代码。但是,将其与Google Drive API一起使用会导致“需要登录”错误。如何将“node-rest-client”npm软件包与Google Drive API一起使用?
这是代码。
const fs = require('fs-extra') // this will have all of a copy of the normal fs methods as well https://www.npmjs.com/package/fs.extra
var inFileId = 'DELETED-INFO' // january 7 from david
var Client = require('node-rest-client').Client
var client = new Client()
// define args
var args = {
path: { "fileId": inFileId },
// commented out by joe for testing
// data: { test: "hello" }, // data passed to REST method (only useful in POST, PUT or PATCH methods)
// path: { "id": 120 }, // path substitution var
// parameters: { arg1: "hello", arg2: "world" }, // this is serialized as URL parameters
headers: { "test-header": "client-api" } // request headers
}
// register Method - see https://developers.google.com/drive/v3/reference/files/copy
client.registerMethod("joesJsonMethod", "https://www.googleapis.com/drive/v3/files/${fileId}/copy", "POST");
// run registered Method with args == Let her rip - joe
const out = fs.createWriteStream('./stdout.log')
const err = fs.createWriteStream('./stderr.log')
const jconsole = new console.Console(out, err);
client.methods.joesJsonMethod(args, function (data, response) {
// parsed response body as js object
jconsole.log('j-=-= parsed response body as js object' )
jconsole.log(data);
// raw response
jconsole.log('\n\nj-=-= raw response' )
jconsole.log(response);
});
这是stdout.log错误消息。
j-=-= parsed response body as js object
{ error: { errors: [ [Object] ], code: 401, message: 'Login Required' } }
如何将“node-rest-client”npm软件包与Google Drive API一起使用?