Search code examples
pythonnltktwitter-oauthdata-analysis

nltk.twitter is giving 401 error


I am trying to collect tweets and extract the text part for my project. I tried many ways and most of them works just fine for me. Though I stumbled upon this nltk.twitter package and some code snippets to do the same work. The codes are pretty clean and i want to use that. But even the simplest code is giving me 401 error though I have my account at twitter developers' and have all the four keys required.

from nltk.twitter import Twitter
tw = Twitter()
tw.tweets(keywords='love, hate', limit=10)

I took this example from http://www.nltk.org/howto/twitter.html#simple and tried every example that is given. None of them works. And apparently I cannot find why. Thank you for your help in advance.


Solution

  • There is a few things that may have caused this. But I bet it is the time issue as nltk is trying to use the streamer and the time of your computer/server is out of sync.

    Also make sure you install nltk completely. Try

    import nltk
    dl = nltk.downloader.Downloader("http://nltk.github.com/nltk_data/")
    dl.download()