我使用Tweepy API来提取Twitter提要.我想只提取特定语言的所有Twitter提要.语言过滤器仅在track
提供过滤器时有效.以下代码返回406错误:
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(languages=["en"])
Run Code Online (Sandbox Code Playgroud)
如何使用Tweepy从特定语言中提取所有推文?
我目前正在使用Twitter API来检索某些用户发布的推文.为了这个问题,我们将以@justinbieber为例.
使用https://stream.twitter.com/1.1/statuses/filter.json资源时,设置跟随所需的用户ID(@justinbieber = 27260086),并允许它运行,而我只想要@ justinbieber的推文我最终收到了他数百万粉丝发给他的推文.显然这意味着我得到的信息比我想要的多,而且从我发现的内容来看,我有时最终错过了用户自己的推文!
我尝试更改https://dev.twitter.com/docs/streaming-apis/parameters上的每个参数都无济于事.
以下参数说明:
For each user specified, the stream will contain:
Tweets created by the user.
Tweets which are retweeted by the user.
Replies to any Tweet created by the user.
Retweets of any Tweet created by the user.
Manual replies, created without pressing a reply button (e.g. “@twitterapi I agree”).
Run Code Online (Sandbox Code Playgroud)
正如在文档中那样,我会假设没有办法只获取用户的推文而不必自己过滤结果(如前所述,这意味着我最终可能会错过用户自己的推文!)但是我很想知道是否有人知道解决方法.
在任何人建议使用诸如status/user_timeline之类的东西之前,我知道它能够做我想要的,但是它有两个缺点让我继续使用流API:
我想做什么?@justinbieber只是一个高开销的Twitter账户的一个例子.我想使用此代码来检索许多高开销帐户的推文,从而提高速度,并且能够查看每个用户的每条推文都是需求.
我使用以下代码来流式传输我的Twitter帐户收到的邮件 - :
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy import API
from tweepy.streaming import StreamListener
# These values are appropriately filled in the code
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
class StdOutListener( StreamListener ):
def __init__( self ):
self.tweetCount = 0
def on_connect( self ):
print("Connection established!!")
def on_disconnect( self, notice ):
print("Connection lost!! : ", notice)
def on_data( self, status ):
print("Entered on_data()")
print(status, flush = True)
return True …
Run Code Online (Sandbox Code Playgroud) 据我所知,Twitter REST API有严格的请求限制(每15分钟几百次),并且流式API有时更适合检索实时数据.
我的问题是,流API的限制是什么?Twitter引用了他们文档的百分比,但没有具体数量.非常感谢任何见解.
我正在做的事情:
api twitter tweetstream twitter-streaming-api twitter-rest-api
使用 tweepy 运行 python 脚本,该脚本在英语推文的随机样本中流式传输(使用 twitter 流 API)一分钟,然后交替搜索(使用 twitter 搜索 API)一分钟,然后返回。我发现的问题是,大约 40 秒后,流媒体崩溃并出现以下错误:
完整错误:
urllib3.exceptions.ProtocolError: ('连接中断:IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))
读取的字节数可以在 0 到 1000 之间变化。
第一次看到流过早中断,搜索功能提前启动,搜索功能完成后,它再次返回流,第二次再次出现此错误时,代码崩溃。
我正在运行的代码是:
# Handles date time calculation
def calculateTweetDateTime(tweet):
tweetDateTime = str(tweet.created_at)
tweetDateTime = ciso8601.parse_datetime(tweetDateTime)
time.mktime(tweetDateTime.timetuple())
return tweetDateTime
# Checks to see whether that permitted time has past.
def hasTimeThresholdPast():
global startTime
if time.clock() - startTime > 60:
return True
else:
return False
#override tweepy.StreamListener to add logic to on_status
class StreamListener(StreamListener):
def on_status(self, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试浏览特定用户的推文并获得该推文的所有回复.我发现twitter的APIv1.1不直接支持它.
获取特定推文的回复是否存在攻击或解决方法?我正在使用python Streaming API.
我正在编写一个Python脚本,pycurl
用于使用Twitter的Sreaming API.这是一个简短的代码片段(只需将您的Twitter登录名/密码进行测试):
import pycurl
user = 'USER'
password = 'PWD'
def handleData(data):
print(data)
conn = pycurl.Curl()
conn.setopt(pycurl.USERPWD, "%s:%s" % (user, password))
conn.setopt(pycurl.URL, 'https://stream.twitter.com/1/statuses/sample.json')
conn.setopt(pycurl.WRITEFUNCTION, handleData)
conn.perform()
Run Code Online (Sandbox Code Playgroud)
问题是因为脚本使用流,所以conn.perform()
永远不会返回(或很少).因此,我有时需要中断脚本,并且KeyboardInterrupt
被perform()
方法捕获.
但是,它不能很好地处理它,打印出一个丑陋的错误,并引发一个不同的异常.
^CTraceback (most recent call last):
File "test.py", line 6, in handleData
def handleData(data):
KeyboardInterrupt
Traceback (most recent call last):
File "test.py", line 12, in <module>
conn.perform()
pycurl.error: (23, 'Failed writing body (0 != 2203)')
Run Code Online (Sandbox Code Playgroud)
该卷曲FAQ说,中断正在进行的转移,回调函数(在我的情况handleData
),应返回的特殊值.这很棒,但是KeyboardInterrupt
没有被任何回调功能捕获!
我怎么能整齐地做到这一点? …
我使用twitter4j连接到Stream API.
据我所知,从这篇帖子中,更改Twitter流过滤关键字而无需重新打开流,在连接打开时无法更改关键字.我必须断开连接并更改过滤器谓词并重新连接它.
我想知道是否有任何代码示例可以让我断开它,更改关键字并重新连接它?
目前,我尝试在onStatus()下的StatusListener中执行此操作,在经过X时间后,它会将关键字更改为"juice".但是我没有办法关闭连接并重新连接到Stream API.
if (diff>=timeLapse) {
StatusListener listener = createStatusListener();
track = "juice";
twitterStream = new TwitterStreamFactory().getInstance();
twitterStream.addListener(listener);
FilterQuery fq = new FilterQuery();
fq.track(new String[] {track});
startTime=System.currentTimeMillis();
twitterStream.filter(fq);
}
Run Code Online (Sandbox Code Playgroud) 我使用twitter streaming api
及johnny-five
与其他一些模块http
,express
及socket.io
用arduino uno
我的脚本在笔记本电脑上运行良好.但我的制作将在平板电脑上.我有两个平板电脑,两者都有不同的反应.在hp omni
平板电脑上我收到以下错误
此外,我已arduino-uno
连接端口,COM3
但其显示设备已连接COM1
据我所知,这个错误是standard firmata
在arduino没有上传的时候引起的.我上传了这个程序,它在笔记本电脑上运行良好
在Acer
平板电脑上我没有收到任何错误程序启动完全没有任何问题,但我没有收到推文twitter streaming api
我已多次交叉检查它在笔记本电脑上运行完全正常,每次我运行它,但给出了两个不同的问题 tablets
这是我正在使用的代码
var Twitter = require('twitter');
var five = require("johnny-five");
var express = require('express')
, app = express()
, http = require('http')
, server = http.createServer(app)
, io = require('socket.io').listen(server);
server.listen(8080);
// routing
app.use(express.static(__dirname + '/http'));
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', "http://"+req.headers.host+':80');
res.setHeader('Access-Control-Allow-Methods', …
Run Code Online (Sandbox Code Playgroud) javascript node.js twitter-streaming-api arduino-uno johnny-five
Twitter Streaming API可用于使用以下查询检测短语:http: //stream.twitter.com/1/statuses/filter.json?track = words
但是,删除推文时似乎没有检测到相同的查询.有没有办法用API做到这一点?
提前致谢.
twitter ×7
python ×5
tweepy ×4
api ×2
arduino-uno ×1
curl ×1
javascript ×1
johnny-five ×1
nlp ×1
node.js ×1
pycurl ×1
tweets ×1
tweetstream ×1
twitter4j ×1