正如問題所述,我想檢查一下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