Pages

Ads 468x60px

Labels

Linkie ♥

16 January, 2013

Python-Twitter Install on MK802 Lubuntu




After you install Lubuntu OS on MK802 or Lubuntu os. Next step to install python-Twitter
on root user.

Register Twitter Develop Account.
  • Go to https://dev.twitter.com/apps/new and log in, if necessary
  • Supply the necessary required fields, accept the TOS, and solve the CAPTCHA.
  • Submit the form

  • Copy the consumer key (API key) and consumer secret from the screen into your application
consumer_key = ‘ConsumerKey######’
consumer_secret = ‘ConsumerSecret######

Python-Twitter Dependencies Install

python-setuptools
root@linaro-alip:~# apt-get install python-setuptools
HTTPLib2 (installed along with oauth2 if you use setuptools)  from  http://code.google.com/p/httplib2/
# wget https://httplib2.googlecode.com/files/httplib2-0.7.7.tar.gz
# tar zxvf httplib2-0.7.7.tar.gz
# cd httplib2-0.7.7httplib2-0.7.7
# python setup.py install
# wget http://pypi.python.org/packages/source/s/simplejson/simplejson-3.0.7.tar.gz
# tar zxvf simplejson-3.0.7.tar.gz
# cd implejson-3.0.7
# simplejson-3.0.7
# python setup.py install
# wget http://pypi.python.org/packages/source/o/oauth2/oauth2-1.5.211.tar.gz
# tar zxvf oauth2-1.5.211.tar.gz # cd oauth2-1.5.211/oauth2-1.5.211
# python setup.py install

Install Python-Twitter

Download and install python-twitter
# wget https://python-twitter.googlecode.com/files/python-twitter-0.8.2.tar.gz
# tar xvf python-twitter-0.8.2.tar.gz
# cd python-twitter-0.8.2
# sudo python setup.py build
# sudo python setup.py install
Config python-twitter you twitter develop account. (Please register twitter develop account first)
# vi get get_access_token.py
   consumer_key = ‘ConsumerKey######’
   consumer_secret = ‘ConsumerSecret######’
Get access token for you Python-Twitter app.
# python get_access_token.py
   Requesting temp token from Twitter
   Please visit this Twitter page and retrieve the pincode to be usedin the next step to obtaining an
   Authentication Token: https://api.twitter.com/oauth/authorize?oauth_token=HQ1YehrXs78GLGUp2IKxZDsA468fLTXBrZDIaGPZiPU   Open URL on browser and login to twitter. and click Authorize app

   Get pincode to python get_access_token.py step.

  Pincode? ######
   Generating and signing request for an access token
   Your Twitter Access Token key: TokenKey: ######
   Access Token secret: TokenSecret######

Testing

Get twitter frend form you accoung
# vi twgetfrend.py
  #!/usr/bin/python
  import twitter
  CONSUMER_KEY = '######'
  CONSUMER_SECRET = '######'
  ACCESS_TOKEN = '######'
  ACCESS_SECRET = ''######'
  mytwitteraccount = twitter.Api(consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET, access_token_key=ACCESS_TOKEN , access_token_secret=ACCESS_SECRET)
  friends=mytwitteraccount.GetFriends()
  print[u.name for u in friends]
# python twgetfrend.pt
Tweets to you account
# vi twhello.py
  #!/usr/bin/python
  import twitter
  CONSUMER_KEY = '######'
  CONSUMER_SECRET = '######'
  ACCESS_TOKEN = '######'
  ACCESS_SECRET = ''######'
  mytwitteraccount = twitter.Api(consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET, access_token_key=ACCESS_TOKEN , access_token_secret=ACCESS_SECRET)
  status=mytwitteraccount.PostUpdates('Hello Twitter from MK802 over Python-Twitter API')
  print status.text
# python twhello.py
 

Link

0 comments:

Post a Comment