尝试运行这个twitter python bot。它基本上需要设置令牌(已经是seted)和hashtag来搜索和收藏。我是新手编码所以我真的不知道我要去哪里。刚从github克隆此代码并尝试运行它。运行python 2.7.2
Connection refused
我已经更改了令牌信息和内容,但我收到了这个错误:
"""
A simple Twitter bot using the Twitter Python library that finds users who tweet about "Christmas gift ideas,"
favorites their tweet, follows the users and sends them a friendly tweet with Amazon links of popular gift ideas.
"""
import urllib
import simplejson
import twitter
consumer_key = ''
consumer_secret = ''
access_token_key = ''
access_token_secret = ''
def searchTweets(query):
search = urllib.urlopen("http://search.twitter.com/search.json?q="+query)
dict = simplejson.loads(search.read())
return dict
api = twitter.Api(consumer_key = 'consumer_key', consumer_secret = 'consumer_secret', access_token_key = 'access_token_key', access_token_secret = 'access_token_secret')
tweets = searchTweets("hashtag")
msg = "Tweet message"
for i in range(len(tweets["results"])):
tweeter = tweets["results"][i]["from_user"]
status = twitter.Api.GetStatus(api, tweets["results"][i]["id"])
api.CreateFavorite(status)
api.CreateFriendship(tweeter)
api.PostUpdate('@' + tweeter + ' ' + msg)
我做错了什么?我正在使用Traceback (most recent call last):
File "TwitterBot.py", line 26, in <module>
for i in range(len(tweets["results"])):
KeyError: 'results'
安装的python-twitter
模块。