Geesh_SO
Geesh_SO

Reputation: 2205

Having trouble accessing Twitter API 1.1 instead of API 1.0 in Python (Django)

At the moment, the code which accesses Twitter is simple and performs a simple search

def parsetwitter():
    api = twitter.Api([KEY-HERE], [KEY-HERE], [KEY-HERE], [KEY-HERE])
    statuses = api.GetSearch('#king')
    for s in statuses:
        print s.text.encode("utf8")
    return statuses

Now I thought this was working fine, and I thought this was using API 1.1 as I was logging in using OAuth but when the API 1.0 blackout happened, this went down...

So I figure I need help in two areas.

A. How do I modify the current code to ensure it is using API 1.1?

B. I know the following method is guaranteed to use API 1.1 but I don't know how to login with OAuth using this method.

https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4

Upvotes: 0

Views: 657

Answers (1)

catherine
catherine

Reputation: 22808

Is this what you mean?

>>> import twitter
>>> client = twitter.Api()
>>> latest_posts = client.GetUserTimeline("yourusername")
>>> print [s.text for s in latest_posts]

This is a sample using authentication:

>>> client = twitter.Api(username='yourusername', password='yourpassword')
>>> update = client.PostUpdate('The Twitter API is easy')

I will also give you a link for Python Library Documentation:

http://static.unto.net/python-twitter/0.5/doc/twitter.html

Upvotes: 1

Related Questions