我正在使用Twitter API来获取流数据
for tweet in api.GetStreamFilter(locations=-122.75,36.8,-121.75,37.8):
print (tweet)
break
当我尝试按位置过滤时收到错误消息
File "<ipython-input-28-51193e42f674>", line 2
for tweet in api.GetStreamFilter(locations=-122.75,36.8,-121.75,37.8):
^
***SyntaxError: positional argument follows keyword argument***
如果我使用过滤器一个单词
for tweet in api.GetStreamFilter(track = 'Facebook'):
print (tweet)
break
它工作正常。
当我使用位置然后我收到错误。
我正在关注
https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters
它说位置
Parameter value Tracks Tweets from...
-122.75,36.8,-121.75,37.8 San Francisco
-74,40,-73,41 New York City
-122.75,36.8,-121.75,37.8,-74,40,-73,41
San FranciscoOR New York City
我收到以下错误
TypeError Traceback (most recent call last)
<ipython-input-37-bd71c23fee89> in <module>()
1
----> 2 for tweet in api.GetStreamFilter(locations=(-122.75,36.8,-121.75,37.8)):
3 print (tweet)
4 break
~\AppData\Local\Continuum\anaconda3\lib\site-packages\twitter\api.py in GetStreamFilter(self, follow, track, locations, languages, delimited, stall_warnings, filter_level)
4580 data['track'] = ','.join(track)
4581 if locations is not None:
-> 4582 data['locations'] = ','.join(locations)
4583 if delimited is not None:
4584 data['delimited'] = str(delimited)
TypeError: sequence item 0: expected str instance, float found
api.GetStreamFilter(locations=-122.75,36.8,-121.75,37.8)
在函数调用的上下文中,逗号的主要用途是分隔参数。
因此,您使用四个参数调用函数:locations=-122.75
,36.8
,-121.75
和37.8
。这是一个错误,因为关键字参数必须在位置(即常规)参数之后。
如果您的意图是传递元组,请将其括在括号中以将其视为单个参数:
api.GetStreamFilter(locations=(-122.75,36.8,-121.75,37.8))