【问题标题】:How to get tweets with coordinates using twython如何使用 twython 获取带有坐标的推文
【发布时间】:2015-05-13 11:55:49
【问题描述】:

我正在尝试获取推文,这里是地理代码

    twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)

searches = twitter.search_geo(q=keywords, lat = '25.032341', long = '55.385557', count=1, rad = '100mi')
print (searches)

得到结果却没有得到推文

{'query': {'type': 'search', 'url': 'https://api.twitter.com/1.1/geo/search.json?lat=25.032341&long=55.385557&rad=100mi&q=++-RT&count=1', 'params': {'coordinates': {'type': 'Point', 'coordinates': [55.385557, 25.032341]}, 'trim_place': False, 'query': '', 'autocomplete': False, 'granularity': 'neighborhood', 'accuracy': 0.0}}, 'result': {'places': [{'name': 'Dubai', 'contained_within': [{'name': 'United Arab Emirates', 'place_type': 'country', 'bounding_box': {'type': 'Polygon', 'coordinates': [[[51.2938738, 22.6261387], [51.2938738, 26.2823697], [56.3816989, 26.2823697], [56.3816989, 22.6261387], [51.2938738, 22.6261387]]]}, 'full_name': 'United Arab Emirates', 'centroid': [55.147370403855, 24.3556033], 'country': 'United Arab Emirates', 'country_code': 'AE', 'attributes': {}, 'url': 'https://api.twitter.com/1.1/geo/id/3f63906fc8aa5a7d.json', 'id': '3f63906fc8aa5a7d'}], 'place_type': 'admin', 'bounding_box': {'type': 'Polygon', 'coordinates': [[[54.8939725, 24.6182526], [54.8939725, 25.3686719], [56.2083722, 25.3686719], [56.2083722, 2

任何人都可以帮助我如何分离推文

【问题讨论】:

  • 您正在尝试使用 this 的等效项。这只会找到给定经度和纬度附近的地理位置,这些地理位置可以在推文上作为place_id 传递。您是否尝试从给定地理位置检索推文?

标签: python twitter twython


【解决方案1】:

Twython 中,search_geo 方法用于为提供的地理位置半径内的“地点”查找place_id。您需要像这样使用search 方法:

from twython import Twython, TwythonError


app_key = 'your_app_key'
app_secret = 'your_app_secret'
oauth_token = 'your_oauth_tokem'
oauth_token_secret = 'your_oauth_secret'

twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)

geocode = '25.032341,55.385557,100mi' # latitude,longitude,distance(mi/km)

try:
    searches = twitter.search(count=1, geocode=geocode)
    print(searches)
except TwythonError as e:
    print(e)

【讨论】:

  • 我的答案是使用与您不同的方法(获取实际推文的方法,而不仅仅是用于附近兴趣点的 place_ids)。上面的代码确实抓取了指定地理编码的推文...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-30
  • 2016-04-14
  • 2021-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多