Tutorial #2:Making Your First API Call (Python)

Here’s an example of how to make a call to our Sentiment HQ API.

import indicoio
indicoio.config.api_key="Your API key here"
sentiment = indicoio.sentiment_hq("Meditating on happiness makes me very happy.")
print sentiment

To run this script, pull up your terminal (or command prompt) and navigate to the folder that you saved this script by using ls to list the contents of the current folder and cd to change to the folder you want. Then, run the command python followed by the filename. 

$ python trying-indico.py

The sentiment of “Meditating on happiness makes me very happy” is 0.994. The closer the value is to 1 the more positive sentiment it is. Likewise, the closer to 0 the more negative the sentiment is. Looking good!

Try using an article URL!

import indicoio
indicoio.config.api_key="Your API key here"

sentiment = indicoio.sentiment_hq("http://www.vanityfair.com/news/2015/10/the-serious-problem-with-treating-donald-trump-seriously", url=True)

print "Sentiment of the article is: {0}".format(sentiment)
# Let's get some keywords too! (This is a comment by the way. Comments aren't run as code, but just act as notes from one programmer to another.)

keywords = indicoio.keywords("http://www.vanityfair.com/news/2015/10/the-serious-problem-with-treating-donald-trump-seriously", url=True, top_n=5)

print "Top 5 keywords of the article are:\n{0}".format(keywords)

Woo, now you're all set up! Next step? Try building some apps -- get started with this tutorial, Foundations for Building a Flask + indico Web App, or check out other use cases + tutorials in our Help Center! 

Did this help answer your question?

thumbs up
thumbs down

Thanks for the feedback! 🙏🏽

Help by drift