I'm trying to create a bot that will retweet and promote some of my other accounts. But i receive the below error.
我正在尝试创建一个机器人,它将转发并推广我的其他一些帐户。但我收到以下错误。
for tweet in search_results["statuses"]:
TypeError: list indices must be integers, not str
My code is...
我的代码是......
from twython import Twython, TwythonError
app_key = 'KEY'
app_secret = 'KEY'
oauth_token = 'KEY'
oauth_token_secret = 'KEY'
twitter = Twython(app_key,app_secret,oauth_token,oauth_token_secret)
#Setting Twitter's search results as a variable
search_results = twitter.get_user_timeline(sreen_name="SCREENNAME", count = 2,)
try:
for tweet in search_results["statuses"]:
twitter.retweet(id = tweet["id_str"])
except TwythonError as e:
print e
1 个解决方案
#1
0
Based on the documentation get_user_timeline
function returns last n timeline stories as a list. Here, n is passed as count
key word argument.
根据文档,get_user_timeline函数将最后n个时间轴故事作为列表返回。这里,n作为计数关键字参数传递。
So, the problem is that you are trying index a list with a string. which is not possible.So that is causing the problem. This Link can help you move forward.
所以,问题是你正在尝试使用字符串索引列表。这是不可能的。所以这就是问题所在。此链接可以帮助您前进。
#1
0
Based on the documentation get_user_timeline
function returns last n timeline stories as a list. Here, n is passed as count
key word argument.
根据文档,get_user_timeline函数将最后n个时间轴故事作为列表返回。这里,n作为计数关键字参数传递。
So, the problem is that you are trying index a list with a string. which is not possible.So that is causing the problem. This Link can help you move forward.
所以,问题是你正在尝试使用字符串索引列表。这是不可能的。所以这就是问题所在。此链接可以帮助您前进。