【问题标题】:Scraping tweets with rtweet: How to get geolocations (lookup_coords)?使用 rtweet 抓取推文:如何获取地理位置(lookup_coords)?
【发布时间】:2020-05-10 21:34:54
【问题描述】:

我正在尝试从 Twitter 中提取推文并使用 rtweet 将它们绘制成地图。我从网上复制了一些代码。我已经设置好了所有东西(包括 Twitter API 和 Google Maps API)。以下代码可以正常工作:

library(rtweet)
rt <- search_tweets("corona", include_rts=FALSE, "lang:en", geocode = lookup_coords("usa"), n = 10000, type="mixed")

# create lat/lng variables using all available tweet and profile geo-location data
rt <- lat_lng(rt)

# plot map
par(mar = c(0, 0, 0, 0))
maps::map("world", regions="usa", lwd = .25)

# plot lat and lng points ontomap
with(rt, points(lng, lat, pch = 20, cex = .75, col = rgb(0, .3, .7, .75)))

但是,一旦我尝试绘制另一个国家,它就不起作用了。例如,如果我尝试绘制相同的搜索词,但这次我想要一张英国地图,这不起作用:

rt <- search_tweets("corona", include_rts=FALSE, "lang:en", geocode = lookup_coords("uk"), n = 10000, type="mixed")

# create lat/lng variables using all available tweet and profile geo-location data
rt <- lat_lng(rt)

# plot map
par(mar = c(0, 0, 0, 0))
maps::map("world", regions="uk", lwd = .25)

# plot lat and lng points ontomap
with(rt, points(lng, lat, pch = 20, cex = .75, col = rgb(0, .3, .7, .75)))

问题显然是这样的

    rt <- search_tweets("corona", include_rts=FALSE, "lang:en", geocode = lookup_coords("uk"), n = 10000, type="mixed")

导致一个空的数据框。其他国家也是如此。有人知道为什么吗?或者有人知道这样做的另一种方式吗?帮助将不胜感激! :)

【问题讨论】:

    标签: r twitter geolocation rtweet


    【解决方案1】:

    在阅读了很多内容并尝试了不同的事情之后,我找到了答案。真的很简单:

    您不仅需要注册 Google Cloud Platform 并设置 API。但您还需要输入您的信用卡信息并设置账单信息。然后激活一切(Geocoding API、Places 等)。然后它工作:)

    【讨论】:

    • Google Cloud Platform 与 Twitter API 和 R 有什么关系呢?这是因为您使用 Geocoding API 进行坐标查找吗?
    • 我不知道 :D 但我使用地理编码 API。尽管如此,我仍不清楚为什么它适用于美国数据,但不适用于其他国家/地区。
    猜你喜欢
    • 2018-12-09
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多