0

我安装了 twitter wrapper for python 安装并运行它但得到这个错误

Traceback (most recent call last):
  File "/home/siddhartha/workspace/trouveunappart/src/test.py", line 35, in <module>
    sid()
  File "/home/siddhartha/workspace/trouveunappart/src/test.py", line 12, in sid
    t = Twitter(
NameError: global name 'Twitter' is not defined

代码是:

from twitter import *



CONSUMER_KEY = ''
CONSUMER_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_SECRET = ''


t = Twitter(
                auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
                CONSUMER_KEY, CONSUMER_SECRET)
            )




since_ID = -1
max_ID = 0

while(since_ID != max_ID):
    search = t.search.tweets(q = k, count = 100, since_id = max_ID)

    print len(search['statuses'])
    if len(search['statuses']) == 0:
        print 'end'
        break


    since_ID = search['search_metadata']['since_id_str']
    max_ID = search['search_metadata']['max_id_str']
4

1 回答 1

3

只是一个猜测。您是否有可能安装了另一个 Twitter 库?我的意思是,import twitter对你有用,但如果你真的在使用python twitter 工具twitter.Twitter,就不应该在那里。

例如,python-twitter没有twitter.Twitter,但有,在python twitter 工具twitter.Api中不存在。似乎你有python-twitter,而不是python twitter tools

于 2013-06-01T20:46:51.930 回答