正如问题所述,我想检查一下twitter用户ID列表的状态。我有大约20k的推特用户。我能够获得大约一半的时间表。其他人可能已被暂停,停用或有0条推文。我发现这个脚本在线,据说可以检查twitter用户的状态。这里是脚本(https://github.com/dbrgn/Twitter-User-Checker/blob/master/checkuser.py): `我想检查一下twitter用户ID列表的状态
#!/usr/bin/env python2
# Twitter User Checker
# Author: Danilo Bargen
# License: GPLv3
import sys
import tweepy
import urllib2
try:
import json
except ImportError:
import simplejson as json
from datetime import datetime
auth = tweepy.AppAuthHandler("xxx", "xxxx")
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
if (not api):
print ("Can't Authenticate")
sys.exit(-1)
# Continue with rest of code
try:
user = sys.argv[1]
except IndexError:
print 'Usage: checkuser.py [username]'
sys.exit(-1)
url = 'https://api.twitter.com/1.1/users/show.json?id=%s' % user
try:
request = urllib2.urlopen(url)
status = request.code
data = request.read()
except urllib2.HTTPError, e:
status = e.code
data = e.read()
data = json.loads(data)
print data
if status == 403:
print "helloooooooo"
# if 'suspended' in data['error']:
# print 'User %s has been suspended' % user
# else:
# print 'Unknown response'
elif status == 404:
print 'User %s not found' % user
elif status == 200:
days_active = (datetime.now() - datetime.strptime(data['created_at'],
'%a %b %d %H:%M:%S +0000 %Y')).days
print 'User %s is active and has posted %s tweets in %s days' % \
(user, data['statuses_count'], days_active)
else:
print 'Unknown response'
`
我收到以下错误: File "twitter_status_checker.py", line 16, in <module> auth = tweepy.AppAuthHandler("xxx", "xxxx") File "/Users/aloush/anaconda/lib/python2.7/site-packages/tweepy/auth.py", line 170, in __init__ 'but got %s instead' % data.get('token_type')) tweepy.error.TweepError: Expected token_type to equal "bearer", but got None instead
谁能帮我修正这个错误,以及允许脚本检查每次运行的用户列表而不是一个用户。
这里是HTTP状态代码,我想检查的列表:https://dev.twitter.com/overview/api/response-codes
谢谢。
谢谢@rojeeer。我只有兴趣知道X中的用户x是否活动,如果不是为什么?是否暂停,停用等? 您上面写的代码不会返回错误的类型。例如,我通过用户的此列表:' 的uid = [ '858379747549749249', '862798674891608064', '869677035291127808', '823878900413583363', '863111039986135040', '851767792521146368', '849779141734002688', '753953185857933312', '863051428805398529' ,'847459130017067008','1694924514']',并且只有其中两个返回,因为它们是活动的。 – Aloush87