首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >API不返回Google脚本中的正确数据

API不返回Google脚本中的正确数据
EN

Stack Overflow用户
提问于 2022-10-03 15:58:30
回答 1查看 71关注 0票数 0

我试图获取Wise以将汇率保存到Google,但由于某种原因,返回的数据是不正确的。

它适用于邮递员,但当我通过Google脚本在谷歌页面上发出同样的请求时,脚本数据就不匹配了。

文档中的curl示例

代码语言:javascript
复制
  https://api.transferwise.com/v3/quotes/ \
  -H "Authorization: Bearer <your client credentials token>"
  -H 'Content-type: application/json' \
  -d '{
    "sourceCurrency": "GBP",
    "targetCurrency": "USD",
    "sourceAmount": null,
    "targetAmount": 110 }'

邮递员中的响应:

Google脚本中的请求:

代码语言:javascript
复制
const url = "https://api.transferwise.com/v3/quotes/";
    const response = UrlFetchApp.fetch(url, {
        "method": "POST",
        "headers": {
            "Authorization": "Bearer + mytoken",
            "Content-Type": "application/json"
        },
        "muteHttpExceptions": true,
        "followRedirects": true,
        "validateHttpsCertificates": true,
        "contentType": "application/json",
        "payload": JSON.stringify({"\\\"sourceCurrency\\\"":"\\\"EUR\\\"","\\\"targetCurrency\\\"":"\\\"USD\\\"","\\\"sourceAmount\\\"":"null","\\\"targetAmount\\\"":"1000"})
    });

  const data = JSON.parse(response.getContentText())

    Logger.log("Response code is %s", response.getResponseCode());
    Logger.log(data.rate);
} 

控制台上的响应:

API返回的是"1.0176“而不是"0.98015”,我无法发现自己做错了什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-03 16:46:19

将有效载荷更改为:

代码语言:javascript
复制
 "payload": `{
  "sourceCurrency": "EUR",
  "targetCurrency": "USD",
  "souceAmount": 1000,
  "targetAmount": null 
 }`
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73937942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档