使用Google Apps脚本的Mashape API出现问题
我已经使用谷歌应用程序脚本有一段时间了,但有些人总是挂断了这个有效负载的东西。我只是想对mashape做一个基本的api调用。由于这是一个post调用,我非常确定我应该在参数选项中使用有效负载,但不确定是什么导致了我的错误。这是我的密码:使用Google Apps脚本的Mashape API出现问题,api,google-apps-script,payload,mashape,Api,Google Apps Script,Payload,Mashape,我已经使用谷歌应用程序脚本有一段时间了,但有些人总是挂断了这个有效负载的东西。我只是想对mashape做一个基本的api调用。由于这是一个post调用,我非常确定我应该在参数选项中使用有效负载,但不确定是什么导致了我的错误。这是我的密码: function mashapeTextSentiment(text){ var key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; var url = "https://japerk-text-process
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
}
工作起来很有魅力!多谢各位