Gaurav Sood
Gaurav Sood

Reputation: 155

access twitter HomeTimeline of user

I am trying to develop a gtk3 desktop application using python to perform the basic twitter functions like accessing the home timeline of a user, making tweets etc.

I am using python-twitter library, but am unable to find the API call for the purpose. I checked and saw there were a few patches , but they dont seem to work. the rest of the functions I am able to accomplish using the library.

I need help!!!

[edit] this is the error i am facing when i tried using a fork of the python-twitter library, as given on: http://github.com/jaytaylor/python-twitter-api

Error:
>>api.getUserTimeline('gaurav_sood91')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "twitter.py", line 2646, in getUserTimeline
    self._checkForTwitterError(data)
  File "twitter.py", line 3861, in _checkForTwitterError
    if data.has_key('next_cursor'):
AttributeError: 'list' object has no attribute 'has_key'

Upvotes: 1

Views: 2434

Answers (1)

Bryan
Bryan

Reputation: 17703

Using the python-twitter module from code.google.com, documentation here.

Accessing user timelines:

import twitter
api = twitter.Api()
statuses = api.GetUserTimeline('@gaurav_sood91')
print [s.text for s in statuses]

Posting tweets:

import twitter
api = twitter.Api(consumer_key='consumer_key',
                  consumer_secret='consumer_secret',      
                  access_token_key='access_token',   
                  access_token_secret='access_token_secret')
status = api.PostUpdate('This is my update text.')

Edit for applying GetHomeTimeline patch:

Disclaimer: I'm on Windows, so you may need to change these steps a bit.

  • Download python-twitter
  • Extract to folder
  • Download 0002-Support-for-home-timeline.patch file from issue 152
  • Copy/move patch file to root of extracted python-twitter directory (there should be a file named twitter.py in this dir)
  • Run command: patch twitter.py 0002-Support-for-home-timeline.patch, you should get a message that patch succeeded
  • In same directory, run command: python setup.py install
  • Run interactive python shell: import twitter, dir(twitter.Api)

You should see the GetHomeTimeline method listed.

Update for GetHomeTimeline:

Found patch in issue 152 that works well using OAuth and JSON parse method that is now part of Status class. Sample code:

import twitter
api = twitter.Api(consumer_key='consumer_key',
                  consumer_secret='consumer_secret',      
                  access_token_key='access_token',   
                  access_token_secret='access_token_secret')
statuses = api.GetHomeTimeline()
print [s.text for s in statuses]

Upvotes: 2

Related Questions