繁体   English   中英

使用Node.js在Twitter中按位置搜索

[英]Search by location in Twitter using nodejs

我正在尝试根据位置搜索推文

我写了下面的代码以按主题标签搜索

Twitter.get('search/tweets', {  q: '#javascript since:7 days', count: 100 }, function (err, data, response) {
      if(!err) { res.send(data.statuses); }
      })

以同样的方式,我尝试通过以下数据中的位置进行搜索。 我找不到按位置搜索的正确关键字。

 { statuses:
  [ { created_at: 'Mon Aug 19 03:01:56 +0000 2019',
   id: 1163284936125759500,
   id_str: '1163284936125759490',
   text:
    'THE <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7019343f3c3d3023243522">',
   truncated: true,
   entities: [Object],
   metadata: [Object],
   source:
    '<a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a>',
   in_reply_to_status_id: null,
   in_reply_to_status_id_str: null,
   in_reply_to_user_id: null,
   in_reply_to_user_id_str: null,
   in_reply_to_screen_name: null,
   user: [Object],
   geo: null,
   coordinates: null,
   place: null,
   contributors: null,
   is_quote_status: false,
   retweet_count: 0,
   favorite_count: 1,
   favorited: false,
   retweeted: false,
   lang: 'en' }]}

我们如何搜寻。 请帮忙

通过Twitter API,您可以指定地址解析参数,以搜索具有给定纬度/经度半径的用户的推文。 参数值由“纬度,经度,半径”指定,其中半径单位必须指定为“ mi”(英里)或“ km”(公里)。

Twitter API文档中有更多详细信息

// Look for tweets from users within 100km of London
let loc = "51.5074,0.1278,100km";
Twitter.get('search/tweets', {  q: '#javascript since:7 days', geocode: loc, count: 10 }, function (err, data, response) {
    if(!err) { res.send(data.statuses); }
})

您还可以查看返回的tweet对象的user.location属性(例如tweet.user.location)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM