Sentiment Analysis

免费增值
Verified
通过 Twinword API | 已更新 il y a 16 jours | Text Analysis
人气

9.6 / 10

延迟

223ms

服务等级

100%

Health Check

N/A

返回所有讨论

Are template literals allowed in text body?

Rapid account: Clairelesage
clairelesage
il y a 7 ans

Hi,

I’m trying to run sentiment analysis on an array of strings. For each comment, it should be passed in as a variable, so in my .send(), I’m using a template literal like this:

for (var i =0; i < arr.length; i++) {
	unirest.post("https://twinword-sentiment-analysis.p.mashape.com/analyze/")
	.header("X-Mashape-Key", "hJ93r96nlcmshNJ46fV3i5wQ4CJQp1K7aY2jsnrISjdiAeRtev")
	.header("Content-Type", "application/x-www-form-urlencoded")
	.header("Accept", "application/json")
	.send(`text=${i}`)
	.end(function (result) {
	  console.log(result.status, result.headers, result.body);
	});
}

Any ideas why it’s not being recognized as a variable?
Thanks.

Rapid account: Twinword
twinword Commented il y a 7 ans

Hi clairelesage,

First, thanks for using our API! Now onto the issue. This error has been found before and it is an issue with PHP Unirest. Two solutions have been found so far:

  1. remove “Content-Type”, OR

  2. use GET method instead of POST method.

We have tested our endpoint on our end (without Unirest) and sending a request with request header “Content-Type” set to “application/x-www-form-urlencoded” has no errors and outputs as expected (as long as in the form data there is a “text” field with some string as its value, ie. text=hello).

On a side note, the header instructions/example on the documentation page is set by Mashape. It is unfortunate that that code example doesn’t work for some odd reason. Nonetheless, the two solutions above would suffice. We and others have already notified Mashape, the people behind Unirest about this bug.

I hope this clears a few things up. If you have any more questions or suggestions, please feel free to let me know or email help@twinword.com directly!

Thanks and happy coding,

Team Twinword

加入讨论 - 在下面添加评论:

登录/注册以发布新的评论