问题与Mashape API使用谷歌应用程序脚本



我已经使用Google Apps Script有一段时间了,但有些人总是挂在这个有效载荷的事情上。我只是想对mashape做一个基本的api调用。因为这是一个post - call,我很确定我应该在参数选项中使用有效载荷,但不确定是什么导致了我的错误。下面是我的代码:

function mashapeTextSentiment(text){
  var key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  var url = "https://japerk-text-processing.p.mashape.com/sentiment/";
  var language = "english";
  var payload = {
    "X-Mashape-Key": key,
    "language": language,
    "text": text
  };
  var options = {
    "method": "post",
    "payload": payload
  };
  var response = UrlFetchApp.fetch(url, options);
  var rs = JSON.parse(response.getContentText());
  return rs;
}
function testMashapeTextSentiment(){
  Logger.log(mashapeTextSentiment("Someone please help me with this!"));
}

这是它给我的错误:

Request failed for https://japerk-text-processing.p.mashape.com/sentiment/ returned code 401. Truncated server response: {"message":"Invalid Mashape application key provided"} (use muteHttpExceptions option to examine full response) (line 17, file "Code")

我在Mashape工作(免责声明),我看了我们的代码,这是一个问题的头-这是一个工作片段!

祝你一切顺利,

function mashape_all_things() {

var url = "https://japerk-text-processing.p.mashape.com/sentiment/";
  var language = "english";
  var text = "mashape's orlie is the great overlord"
  var payload = {
    "language": language,
    "text": text
  };
  var options = {
    "method": "post",
    "headers": { //this is where you went wrong, you didnt pass the header properly
      "X-Mashape-Key": "XXXXXXXXXXXXXXXXXX"
    },
    "payload": payload
  };
  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response);
  return
}

相关内容

  • 没有找到相关文章

最新更新