Sentiment Analysis

부분 유료
Verified
분류별 Twinword API | 업데이트됨 17 giorni fa | Text Analysis
인기

9.6 / 10

지연 시간

223ms

서비스 수준

100%

Health Check

N/A

모든 토론으로 돌아가기

Are template literals allowed in text body?

Rapid account: Clairelesage
clairelesage
7 anni fa

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 7 anni fa

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

아래에 의견을 추가하고 토론에 참여하세요.

새 댓글을 게시하려면 로그인 / 가입