Python 将get\u followers\u id与lookup\u user一起使用
我有一个id列表存储为类型dict_值。我想使用此列表作为查找用户的输入,但格式似乎不正确。我知道lookup_用户通常接受逗号分隔的值字符串。有没有办法将我的dict值列表转换成这种格式 以下是我目前的代码:Python 将get\u followers\u id与lookup\u user一起使用,python,twitter,twython,Python,Twitter,Twython,我有一个id列表存储为类型dict_值。我想使用此列表作为查找用户的输入,但格式似乎不正确。我知道lookup_用户通常接受逗号分隔的值字符串。有没有办法将我的dict值列表转换成这种格式 以下是我目前的代码: import sys import string import simplejson from twython import Twython import datetime now = datetime.datetime.now() day=int(now.day) month=int
import sys
import string
import simplejson
from twython import Twython
import datetime
now = datetime.datetime.now()
day=int(now.day)
month=int(now.month)
year=int(now.year)
twitter = Twython()
out_file_name = "1339835893_follower_ids_%i.%i.%i.txt" % (now.month,
now.day,
now.year)
followers = twitter.get_followers_ids(id = "1339835893") # or just () - followers for your account
#print(followers)
#for follower_id in followers:
keys = followers.viewkeys()
values = followers.viewvalues()
print values.__class__
users = twitter.lookup_user(user_id = values) # breaks here
我希望你已经为你的问题找到了答案。如果你没有,这里有一个快速的答案 您正在传递一个dict_values对象作为user_id的参数。此字段接受id列表或逗号分隔的id字符串。有关该功能的更多信息,请参阅 对我来说,一个快速的改变就是改变:
users = twitter.lookup_user(user_id = values) # breaks here
进入:
因为followers对象是一个字典,所以可以通过使用“id”索引字段来检索它。(如果愿意,您也可以使用followers.get('id')。无论如何,这会返回twython和twitter想要的列表
users = twitter.lookup_user(user_id=followers['ids'])