I try to use the sample code of nodejs to convert word to pdf .But this ‘Error: Authorization failed’
occurred .I have correctly entered the Client Id and Client Secret of the created Application in the dashboard.The following is the code and error message.
const { WordsApi, ConvertDocumentRequest } = require("asposewordscloud");
const fs = require("fs");
const clientId = "0a182d30-ea11-4ca4-855a-xxxxxxxxxxxx";
const secret = "96677b1d6218fb17c3654xxxxxxxxxxxxxx";
const wordsApi = new WordsApi(clientId, secret);
// Convert Word Document to PDF (the output will be saved in Cloud storage)
var fileName = "desol-A.docx";
var request = new ConvertDocumentRequest({
format: "pdf",
document: fs.readFileSync(fileName),
});
wordsApi.convertDocument(request).then((result) => {
fs.writeFile("desol-A.pdf", result.body, (err) => {
if (err) throw err;
console.log("Successfully converted");
});
})
F:\workspace\w2p>node index.js
(node:12848) UnhandledPromiseRejectionWarning: Error: Authorization failed
at F:\workspace\w2p\node_modules\asposewordscloud\dist\internal\requestHelper.js:140:23
at Generator.throw (<anonymous>)
at rejected (F:\workspace\w2p\node_modules\asposewordscloud\dist\internal\requestHelper.js:32:65)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12848) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which
was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejecti
ons_mode). (rejection id: 1)
(node:12848) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit c
ode.