0

我正在尝试从 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")

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

4

1 回答 1

0

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

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

于 2020-05-10T13:34:54.930 回答