我一直在使用Tweepy库使用Twitter Streaming API。我先跟踪自己的帐户,然后在发布它们时流式传输自己的tweet,效果很好。
然后,我尝试流式传输相当大区域的推文([30,-85,31,-84]),最初似乎没有任何数据。然后,我开始接收“位置删除通知”或“ scrub_geo”消息,此后才收到这些消息。我将代码改回了以前的工作遵循代码,但是我继续收到'scrub_geo'消息,而不是个人资料中的状态。
这是我正在使用的脚本:
# Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
# Other libs
import json
# Variables that contains the user credentials to access Twitter API
access_token = "<my_access_token>"
access_token_secret = "<my_secret_token>"
consumer_key = "<my_consumer_key>"
consumer_secret = "<my_consumer_secret>"
# This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):
def on_data(self, data):
#try:
# json_data = json.loads(data)
# print json_data['created_at'] + " " + data['text']
#except:
print "Data " + str(data)
return True
def on_error(self, status):
print "Error " + str(status)
if status == 420:
print("420 error.")
return False
if __name__ == '__main__':
# This handles Twitter authetification and the connection to Twitter Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
# Start streaming with right parameters
#tallahassee=[30,-85,31,-84]
#stream.filter(locations=tallahassee) <---- previously used
stream.filter(follow="<my_user_id>")
您的坐标已反转。既然我们GeoJSON
一直在做,(long,lat,alt)
要么(x,y,z)
因此,您需要提供tallahassee=[-85,30,-84,31]
。始终像(x,y)
在数学中一样先提供经度。
有些地方(例如Google地图)会首先进行纬度。您只需要注意要使用哪种格式即可。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句