我正在使用Tweepy的Stream Listener並希望檢索英國當前政治辯論中的推文。不幸的是,在RT和響應情況下,我只收到了截斷的推文。Tweepy流監聽器用於擴展推文
如: -
RT @ZaidJilani:舒默(antiBDS法案的發起人)說,我們應該扼殺了加沙。傑里米·科爾賓說壓迫他們會...
當fulltweet應該是: -
舒默(antiBDS法案的發起人)說,我們應該扼殺了加沙。傑里米柯賓說,壓制他們只會激化人們。
我看到有一種方法可以使用`tweet_mode = extended與普通的Twitter.API擴展。但是我找不到與Streaming API類似的東西。有沒有人爲此提供解決方案?我的代碼如下: -
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
from redis import Redis
from rq import Queue
import requests
import time
import io
import os
import json
import threading
import multiprocessing
from datetime import datetime, timedelta
import _credentials
# twitter OAuth
ckey = _credentials.ckey
consumer_secret = _credentials.consumer_secret
access_token_key = _credentials.access_token_key
access_token_secret = _credentials.access_token_secret
#Listener Class Override
class listener(StreamListener):
def __init__(self, start_time, time_limit):
self.time = start_time
self.limit= time_limit
self.tweet_data = []
def on_data(self, data):
localtime = datetime.now().strftime("%Y-%b-%d--%H-%M-%S")
print(localtime)
while (time.time() - self.time) < self.limit:
try:
self.tweet_data.append(data)
return True
except BaseException:
print ('failed ondata')
time.sleep(5)
pass
saveFile = io.open(('raw_tweets_{}.json').format(localtime), 'w', encoding='utf-8')
saveFile.write(u'[\n')
saveFile.write(','.join(self.tweet_data))
saveFile.write(u'\n]')
saveFile.close()
exit()
def on_error(self, status):
print (status)
def on_disconnect(self, notice):
print ('bye')
#Beginning of the specific code
keyword_list = ['Theresa May', 'Jeremy Corbyn', 'GE2017', 'Labour', 'Tory','Tories'] #track list
start_time=time.time()
auth = OAuthHandler(ckey, consumer_secret) #OAuth object
auth.set_access_token(access_token_key, access_token_secret)
twitterStream = Stream(auth, listener(start_time, time_limit=10)) #initialize Stream object with a time out limit
twitterStream.filter(track=keyword_list, languages=['en']) #call the filter method to run the Stream Listener
[Twitter Dev Documentation](http://dev.twitter.com/overview/api/upcoming-changes-to-tweets)聲明它在Streaming API中不可用 - 「Streaming API不提供[...]通過公共REST API以兼容模式呈現的Tweets將不包含extended_tweet字段。「 – davedwards