2013-03-06 84 views
0

訪問Twitter的API 1.1,而不是API 1.0目前遇到問題,它訪問Twitter的代碼簡單,並執行一個簡單的搜索在Python(Django的)

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 

現在,我認爲這是工作的罰款,並我以爲這是使用API​​ 1.1,因爲我正在使用OAuth登錄,但是當發生API 1.0停電事故時,此事發生了...

所以我想我需要兩個方面的幫助。

A.如何修改當前代碼以確保它使用API​​ 1.1?

B.我知道以下方法保證使用API​​ 1.1,但我不知道如何使用此方法使用OAuth登錄。

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

回答

1

這是你的意思嗎?

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

這是通過認證的樣本:

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

我也會給你的Python庫文檔的鏈接:

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

+0

我不認爲會與API 1.1,因爲它需要OAuth登錄。 – 2013-03-06 13:08:44

+0

對不起,它會正常工作,因爲我的代碼:P但問題是,現在正在向API 1.1過渡。 API 1.1需要OAuth登錄,並且API 1.0目前只能處於間歇性斷電狀態。 – 2013-03-06 13:10:04

+0

啊,用戶名和密碼 – catherine 2013-03-06 13:15:11