0

我使用 Google Apps Script 已经有一段时间了,但有些人总是被这个有效负载的东西挂断。我只是想对 mashape 进行基本的 api 调用。由于这是一个后调用,我很确定我应该在参数选项中使用有效负载,但只是不确定是什么让我犯了错误。这是我的代码:

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")
4

1 回答 1

1

我在 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
}
于 2014-07-12T11:49:49.387 回答