1

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'
Gaurav Sood
  • 157
  • 3
  • 16
  • What have you tried? I see some examples about what you're asking in the [project home](http://code.google.com/p/python-twitter/). Are you having maybe authentication problems? – jcollado Dec 22 '11 at 16:55
  • there was a github repo, [link]http://github.com/jaytaylor/python-twitter-api[/link] i tried using that, but was unable to use any specific method of the api invloving retrieving status messages etc, even though i saw the methods were present. an error was constantly being shown to me: Traceback (most recent call last): File "", line 1, in 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_ke – Gaurav Sood Dec 22 '11 at 17:02
  • Please improve your question by adding that information to the question. – jcollado Dec 22 '11 at 17:07
  • i added the error i am getting. even though i tried getUserTimeline() function. i was unable to get how to use the getHomeTimeline() function – Gaurav Sood Dec 22 '11 at 17:19

1 Answers1

2

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]
Bryan
  • 17,112
  • 7
  • 57
  • 80
  • that i know. but what i get via the GetUserTimeline() function is only the tweets i make, or replies i give. it does not give me the tweets of people i follow. that comes under the HomeTimeline, which is not given in python-twitter. i gave a link of a patch which is supposed to have added that functionality to it, but am unable to make it work – Gaurav Sood Dec 22 '11 at 17:26
  • Updated answer with link to patch for python-twitter which adds status/home_timeline functionality. – Bryan Dec 22 '11 at 17:45
  • one question: i did not get how to apply the patch. – Gaurav Sood Dec 22 '11 at 17:58
  • Are you on Windows or Unix/Linux? – Bryan Dec 22 '11 at 18:07
  • i did the steps. then patch was successfully installed and then re-installed the python-twitter library. only thing is using the api call. i tried calling it with userid or screen_name as arguments, by seem to get the following error: http://bpaste.net/show/21144/ – Gaurav Sood Dec 23 '11 at 06:59
  • My original examples for posting tweets and retrieving home timeline were incorrect. You need to use OAuth to authenticate for posting or getting home timeline. Examples updated with link to information on OAuth in the Twitter dev pages. – Bryan Dec 27 '11 at 13:28
  • After creating an account and authenticating with OAuth, I'm experiencing the same problems. I added a _username property to the Api object, but it looks like there are JSON parsing methods not implemented for home timelines. – Bryan Dec 27 '11 at 14:02
  • Did some more research and found a patch that worked for python-twitter: http://code.google.com/p/python-twitter/issues/detail?id=152 – Bryan Dec 27 '11 at 20:46