【问题标题】:Using Twitter API with Python (geocode)将 Twitter API 与 Python 一起使用(地理编码)
【发布时间】:2012-01-06 17:37:06
【问题描述】:

如何在 Python 中进行以下调用?伪代码版本:

jsonTwitterResponse = twitter.get(up to max of 3 
                      tweets within 3km of longitude: 7, latitude: 5)
print jsonTwitterResponse

看起来geocode API 是我需要的。我不知道如何实际编码。我将如何在实际代码中执行上述操作?

【问题讨论】:

    标签: python json twitter geocode


    【解决方案1】:

    我认为这个方法可能是最近才添加的:

    import urllib, json, pprint
    
    params = urllib.urlencode(dict(lat=37.76893497, long=-122.42284884))
    u = urllib.urlopen('https://api.twitter.com/1/geo/reverse_geocode.json?' + params)
    j = json.load(u)
    pprint.pprint(j)
    

    文档:https://dev.twitter.com/docs/api/1/get/geo/reverse_geocode

    【讨论】:

      【解决方案2】:

      除了 Raymond Hettinger 的回答之外,我想提一下,如果您不想使用实际坐标,还可以使用 "near:Amsterdam within:5km" 之类的查询。

      示例:http://search.twitter.com/search?q=near:Amsterdam%20within:5km

      【讨论】:

      • 不错。我不知道那个选项:-)
      【解决方案3】:

      这是一个示例地理编码请求:

      import urllib, json, pprint
      
      params = urllib.urlencode(dict(q='obama', rpp=10, geocode='37.781157,-122.398720,1mi'))
      u = urllib.urlopen('http://search.twitter.com/search.json?' + params)
      j = json.load(u)
      pprint.pprint(j)
      

      此处描述了完整的 Twitter REST API:https://dev.twitter.com/docs/api 此外,Twitter 有一个 location search FAQ 可能会引起您的兴趣。

      【讨论】:

        猜你喜欢
        • 2018-01-02
        • 2018-01-24
        • 2013-04-14
        • 2013-06-23
        • 2010-10-14
        • 1970-01-01
        • 1970-01-01
        • 2015-05-05
        • 1970-01-01
        相关资源
        最近更新 更多