0

I am unable to understand what is wrong with my code.when i run it,it gives me the error-RuntimeError: API_KEY not set.please help.Thanks

`import os import sys from helpers import get_user_timeline

from analyzer import Analyzer from termcolor import colored

def main():

# ensure proper usage
if len(sys.argv) != 2:
    sys.exit("Usage: ./tweets @screen name")
user_handle=sys.argv[1].lstrip("@")
print(user_handle)

# absolute paths to lists
positives = os.path.join(sys.path[0], "positive-words.txt")
negatives = os.path.join(sys.path[0], "negative-words.txt")


tweets = get_user_timeline(user_handle, 50)
if tweets == None:
    sys.exit("Not a valid screen name")

# instantiate analyzer
analyzer = Analyzer(positives, negatives)


for tweet in tweets:
   score = analyzer.analyze(tweet)
   if score > 0.0:
    print(colored("{} {}".format(score, tweet), "green"))
   elif score < 0.0:
    print(colored("{} {}".format(score, tweet), "red"))
   else:
    print(colored("{} {}".format(score, tweet), "yellow"))

if name == "main": main() `

1 Answer 1

1

The error is telling you exactly what is wrong: you did not set your API_KEY (or API_SECRET) at the command line before running your program.

Read the "Getting Started" section of the specification carefully. It explains in detail how to set up the Twitter API for use with this assignment.

1
  • True,I didn't set the api_key and api_secret so was getting that error.thanks Commented Jun 28, 2017 at 5:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .