python-推特-api

2 投票
2 回答
1826 浏览
提问于 2025-04-16 13:50
import twitter

client = twitter.Api()

client = twitter.Api(username='uname', password='password')

update = client.PostUpdate('Tweetin from python!')

这是我的代码。
当我运行这个程序时,我遇到了这个错误。

TypeError: __init__() got an unexpected keyword argument 'username'

有人能帮我吗?

2 个回答

1

根据文档,你需要使用OAuth,并在API构造函数中指定密钥和访问令牌:

http://code.google.com/p/python-twitter/

这意味着在使用这个API之前,你需要先获取一些特别的代码和令牌,这样才能安全地访问相关的数据。

>>> api = twitter.Api(consumer_key='consumer_key',
consumer_secret='consumer_secret', access_token_key='access_token', access_token_secret='access_token_secret')

撰写回答