I will demonstrate a basic example of sentiment analysis using in python using jupyter notebook as an editor. We will be analysing tweets from twitter using tweepy. Tweepy is a python library for accessing twitter API.
We start by creating a new app in https://apps.twitter.com/
Once you create an app in twitter, generate the access token and set the permissions (read/write) accordingly. To accomplish this, you need to key in app name, description and a url. Url could be anything in the right format if you don't have one for yourself.
Once the consumer and access secret keys are generated. Next step would be to fire up python in your choice of editor.
I chose jupyter here. Begin by importing tweepy and textblob libraries. textblob is a python library for text processing.
Assign consumer and access key. Use OAuthHandler method of tweepy by passing consumer key and consumer secret. Then call set_access_token method by passing access token and access secret key.
Once this is done, your authentication is done. Now you can use search method and pass in a text string to search for.
I have searched tweets for 'Indian cuisine' and successfully printed the results back via python.
IMPORTANT : Never expose/share Consumer and Access secret key.

No comments:
Post a Comment