Javascript 在GAS上使用基本身份验证API JSON时出现错误400
我正试图通过Google应用程序脚本上的应用程序使用下载文件,但出现以下错误:Javascript 在GAS上使用基本身份验证API JSON时出现错误400,javascript,json,api,google-apps-script,Javascript,Json,Api,Google Apps Script,我正试图通过Google应用程序脚本上的应用程序使用下载文件,但出现以下错误: <?xml version="1.0" encoding="UTF-8"?> <Error> <Code>InvalidArgument</Code> <Message>Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Sig
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidArgument</Code>
<Message>Only one auth mechanism allowed; only the X-Amz-Algorithm
query parameter, Signature string parameter or the Authorization header
should be specified</Message>
<ArgumentName>Authorization</ArgumentName>
<ArgumentValue>Basic ENCODED ID </ArgumentValue>
<RequestId> REQUEST ID </RequestId>
<HostId> HOST ID </HostId>
</Error>
有人知道那是什么吗?我发现了一些关于重新发送头授权的信息,但我不知道如何在GAS上这样做
请在下面找到我的代码:
function zamzar() {
var url = "https://sandbox.zamzar.com/v1/jobs";
var user = API KEY;
var headers = {
"Authorization": "Basic "+ Utilities.base64Encode(user+":"),
"followRedirect": false
};
var options = {
"method" : "post",
"headers" : headers,
"muteHttpExceptions" : true,
};
upload(url, headers, options);
}
function upload(url, headers, options) {
var formData = {
"source_file" : "http://www.sinduscon-rs.com.br/wp-content/uploads/2018/06/VALORES-DOS-CUBS.pdf", //pdf that will be converted to XLS
"target_format" : "xls",
}
options["payload"] = formData;
var response = UrlFetchApp.fetch(url,options);
checkConversion(response, headers);
}
function checkConversion(response, headers) {
Utilities.sleep(10000) // wait 10 seconds to finish conversion
var JSONresponse = JSON.parse(response, headers)
var jobID = JSONresponse.id;
var url = "https://sandbox.zamzar.com/v1/jobs/" + jobID;
var options = {
"method" : "get",
"headers" : headers,
"muteHttpExceptions" : true,
};
var response = UrlFetchApp.fetch(url,options);
var checkResponse = JSON.parse(response);
download(checkResponse, headers);
}
function download(checkResponse, headers) {
var xlsID = checkResponse.target_files[0].id;
var url = "https://sandbox.zamzar.com/v1/files/" + xlsID + "/content";
var options = {
"method" : "get",
"headers" : headers,
"muteHttpExceptions" : true,
};
var response = UrlFetchApp.fetch(url,options);
Logger.log(response);
}
请求
上载():
checkConversion():
下载():
响应
上载():
checkConversion():
下载()
@谢谢你的回复!生成错误的
UrlFetchApp.fetch
是download()
函数中的错误。您确定可以使用驱动API将PDF转换为Google工作表吗?我只能找到转换为Google文档的文档。抱歉,您是正确的-PDF的ocr/转换将只映射到文档文件:。考虑建立要发送的请求并检查它,以获得错误引用的多个授权参数。谢谢你的提示!我将请求附在原始问题之后。我真的不明白那是什么意思。你知道怎么了吗?可能与你的情况有关。您是否能够查看出现错误的响应对象?如果是这样,将其与发送的请求进行比较可能也会有所帮助@再次谢谢你!我再次编辑了我的问题,以包含回答
[18-07-12 09:43:43:082 BRT] {headers={Authorization=Basic Yjc4NzZkZTAwM2ZkZjY3ZGE4MWNkMmMxNmRjMGQ2YTBlOTNkMTNlYTo=, followRedirect=false}, method=post, payload=source_file=http://www.sinduscon-rs.com.br/wp-content/uploads/2018/06/VALORES-DOS-CUBS.pdf&target_format=xls, followRedirects=true, validateHttpsCertificates=true, useIntranet=false, contentType=application/x-www-form-urlencoded, url=https://sandbox.zamzar.com/v1/jobs}
[18-07-12 09:43:53:223 BRT] {headers={Authorization=Basic Yjc4NzZkZTAwM2ZkZjY3ZGE4MWNkMmMxNmRjMGQ2YTBlOTNkMTNlYTo=, followRedirect=false}, method=get, payload=, followRedirects=true, validateHttpsCertificates=true, useIntranet=false, contentType=null, url=https://sandbox.zamzar.com/v1/jobs/3282094}
[18-07-12 09:43:53:423 BRT] {headers={Authorization=Basic Yjc4NzZkZTAwM2ZkZjY3ZGE4MWNkMmMxNmRjMGQ2YTBlOTNkMTNlYTo=, followRedirect=false}, method=get, payload=, followRedirects=true, validateHttpsCertificates=true, useIntranet=false, contentType=null, url=https://sandbox.zamzar.com/v1/files/35530845/content}
[18-07-12 13:03:14:399 BRT] ({'zamzar-credits-remaining':"100", Server:"Apache", 'zamzar-test-credits-remaining':"64", Connection:"keep-alive", 'Content-Length':"354", Date:"Thu, 12 Jul 2018 16:03:14 GMT", 'Content-Type':"application/json; charset=utf-8"})
[18-07-12 13:03:24:538 BRT] ({'zamzar-credits-remaining':"100", Server:"Apache", 'zamzar-test-credits-remaining':"60", Connection:"keep-alive", 'Content-Length':"501", Date:"Thu, 12 Jul 2018 16:03:24 GMT", 'Content-Type':"application/json; charset=utf-8"})
[18-07-12 13:03:24:708 BRT] ({'Transfer-Encoding':"chunked", Server:"AmazonS3", Connection:"close", 'x-amz-request-id':"8C10EE520E590056", 'x-amz-id-2':"tpQ4wZSmNe3GMZV9aCOGA5DoOcZ36ONmYs2drJApbmg5wou/iOWJSkwhH3dKSiyi0ypU4GT9SUc=", Date:"Thu, 12 Jul 2018 16:03:23 GMT", 'Content-Type':"application/xml"})