Sentiment Analysis

フリーミアム
Verified
よって Twinword API | 更新済み vor 17 Tagen | Text Analysis
人気

9.6 / 10

レイテンシー

223ms

サービスレベル

100%

Health Check

N/A

すべてのディスカッションに戻る

Are template literals allowed in text body?

Rapid account: Clairelesage
clairelesage
vor 7 Jahren

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 vor 7 Jahren

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

ディスカッションに参加しましょう-以下にコメントを追加してください:

ログイン/サインアップして新しいコメントを投稿