Creating a twitter app with python

Link

twitter-for-teachers-blog-png

Head to the following link and follow the instructions below. You will need access to a twitter account, and have a github account to view the posted code.

https://github.com/crimeprophet/CodeSaints/blob/master/tweet.py

  • install pip by running: python get-pip.py
  • install tweepy by running: Sripts\pip install tweepy


Code for Notepad:
Create a file called ‘YourName’_Hello_World.py

Ensure that you put the hashtags (#) in front of the lines that have it as it is there to clarify the purpose of the code that follows


import tweepy

# enter your authentication details below (see dev.twitter.com)

consumer_key = ”
consumer_secret = ”
access_token = ”
access_token_secret = ”

# create authentication token

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

# get API handler

api = tweepy.API(auth)

# get text to tweet – should add error check for tweet lengthtweet = raw_input( “Enter text to tweet: ” )

print “Sending tweet “, tweet
api.update_status(‘Tweet via python #CodeSaints: ‘+ tweet)

Leave a Reply