在R

时间:2016-09-13 04:56:21

标签: r twitter leaflet

我现在尝试运行以下代码(R脚本)。我甚至无法检索带有长/对的单个推文。我正在获取文本列。但是,检索到的所有推文的纬度/长度对显示NA(即使对于通用搜索词,如" twitter")。当我在5个月之前运行相同的代码时,我能够检索带有lat / long对的推文。我想问题出在Twitter Search API上。我不知道如何解决这个问题。

(使用API​​凭据保存代码)

/app.R

library(leaflet)
library(twitteR)

  consumerKey <- ""
  consumerSecret <- ""    
  accessToken <- ""
  accessSecret <- ""


    setup_twitter_oauth(consumer_key = consumerKey, consumer_secret = consumerSecret,access_token = accessToken, access_secret = accessSecret)

    mapTweets <- searchTwitteR("donaldtrump", 
                               n = 500, 
                               lang = "en", 
                               geocode = "37,-122,100mi")

    mapTweets.df <- twListToDF(mapTweets)

    mapTweets.df <- mapTweets.df[!is.na(mapTweets.df$longitude), ]


    rendermap <- leaflet() %>% 
      addTiles() %>%
      addMarkers(data = mapTweets.df, lng = mapTweets.df$longitude, lat = mapTweets.df$latitude, popup = mapTweets.df$screenName) %>%
      setView(lng = 37, lat = -122, zoom = 4)

    rendermap

1 个答案:

答案 0 :(得分:0)

默认的Twitter客户端不包括大多数用户的特定纬度/长度。您的搜索范围足够广泛,以便您获取与某个区域内的用户相关的内容或标记为整个城市的内容。

e.g。比较

$ tweetsearch geocode:37,-122,100mi | jq -r '.statuses[] | select(.place) | [.place.name, .coordinates?.coordinates] | flatten | @tsv'
Turlock
Novato
Burbank
Oakland
San Francisco
Oakland
Fresno
San Mateo
Alameda
San Bruno
Hayward
San Jose
Ceres
Fresno
San Jose
San Jose
Discovery Bay
Hayward
Modesto
Berkeley
San Jose
Antioch
San Lorenzo
San Jose
Alameda

$ tweetsearch geocode:37.781157,-122.398720,1mi | jq -r '.statuses[] | select(.place) | [.place.name, .coordinates?.coordinates] | flatten | @tsv'
San Francisco   -122.38977533   37.77854483
San Francisco   -122.38977533   37.77854483
San Francisco   -122.38977533   37.77854483
Mission Bay
San Francisco   -122.38977533   37.77854483
San Francisco   -122.38977533   37.77854483
San Francisco   -122.38977533   37.77854483
San Francisco   -122.4192647    37.7792597
South of Market
San Francisco   -122.418    37.775
San Francisco   -122.4192647    37.7792597
San Francisco   -122.41487603   37.78678264
San Francisco   -122.41487603   37.78678264
San Francisco   -122.418    37.775
South Beach
San Francisco   -122.41640337   37.78025867
San Francisco   -122.39832343   37.77958373