twitter api python

$ pip install tweepy
-
import tweepy

auth = tweepy.OAuthHandler("YOU_CONSUMER_KEY", "YOUR_CONSUMER_SECRET")
auth.set_access_token("YOUR_ACCESS_TOKEN", "YOUR_ACCESS_SECRET")
api = tweepy.API(auth)

# Tweet something
tweet = api.update_status("My first tweet!")

# Like the tweet you just made
api.create_favorite(tweet.id)

Here is what the above code is Doing:
1. We’re creating a new instance of the tweepy.OAuthHandler class. This class is used to authenticate our access to the Twitter API.
2. We’re setting the access token and access secret for our new instance of the tweepy.OAuthHandler class.
3. We’re creating a new instance of the tweepy.API class. This class gives us access to all of the Twitter API methods.
4. We’re creating a new tweet.
5. We’re favoriting the tweet we just created.