【问题标题】:Python twitter API error for Twitter classTwitter 类的 Python twitter API 错误
【发布时间】:2017-11-13 03:17:44
【问题描述】:

我正在尝试使用 python twitter API,但找不到 Twitter 类。 https://pypi.python.org/pypi/twitter

例如,我执行以下操作没有任何错误:

 from twitter import *

但是当我这样做时:

 >>> t = Twitter(auth)
 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 NameError: name 'Twitter' is not defined

我错过了什么?我需要安装其他 python twitter 库吗?

【问题讨论】:

  • 您是否在尝试执行该导入的同一位置创建了一个名为 twitter.py 的文件?
  • 不,我只是从 python REPL 运行
  • 我确实在 SO btw 上看到了其他答案
  • 您的from twitter import * 是否与您的t = Twitter(auth) 命令在同一个REPL 会话中执行?
  • 是的,我只是一个接一个地输入这些行。 auth 在单独的行中设置为 OAuth1(..)。

标签: python twitter python-twitter


【解决方案1】:

尝试使用 tweepy 库,好用。看看http://www.tweepy.org/

这是一个代码示例:

import tweepy

auth = tweepy.OAuthHandler('','')

auth.set_access_token('', '')

api = tweepy.API(auth)

public_tweets = api.followers_ids()
for tweet in public_tweets:
    print len(public_tweets)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-06
    相关资源
    最近更新 更多