Sentiment Analysis

FREEMIUM
Verified
От Twinword API | Обновлено 16 дней назад | Text Analysis
Популярность

9.6 / 10

Задержка

225ms

Уровень обслуживания

100%

Health Check

N/A

Назад ко всем обсуждениям

Are template literals allowed in text body?

Rapid account: Clairelesage
clairelesage
7 лет назад

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 лет назад

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

Присоединяйтесь к обсуждению – добавьте комментарий ниже:

Войдите / Зарегистрируйтесь, чтобы публиковать новые комментарии