NameError:未定义全局名称“Twitter”

时间:2013-06-01 20:36:31

标签: python api twitter twitter-oauth

我安装了python的twitter包装器并安装它并运行它但是出现了这个错误

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']

1 个答案:

答案 0 :(得分:3)

只是一个猜测。您是否可能安装了另一个推特库?我的意思是,import twitter适合你,但如果你真的使用 python twitter工具,那么就不存在twitter.Twitter

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