【问题标题】:Getting location from Twitter profile in R从 R 中的 Twitter 个人资料中获取位置
【发布时间】:2015-05-09 02:15:11
【问题描述】:

我需要能够获取用户的位置,地理编码正在为 searchTwitter() 返回 NA。如何获取配置文件并仅使用 user_name 存储用户的位置?

【问题讨论】:

    标签: r twitter


    【解决方案1】:

    您可以安装和使用R Twitter 包:

    install.packages("twitteR")
    
    # get user object for Kim Kardashian
    user <- getUser("KimKardashian")
    # now you know where Kim Kardashian lives
    print(user$location)
    

    如果您有一个名为 users_df 的数据框也有一个列 username,您可以使用以下代码获取所有用户的位置:

    getLocation <- function(x) {
        y <- getUser(x)
        location <- y$location
        return location
    }
    
    users_df$username
    locations <- sapply(users_df$username, function(x) getLocation(x))
    

    顺便说一句,getUser 调用只有在您尝试访问的个人资料是公开的情况下才会成功。如果你找不到金·卡戴珊住在哪里,就不要养牛。

    【讨论】:

    • 我正在使用 Windows,但出现“tw_from_response(out, ...) 中的错误:未使用的参数 (cainfo = "cacert.pem")”
    • 您可以尝试从对getUser 的调用中删除cainfo 参数吗?
    • 好的! (我无法遵循基本指示)现在我可以使用其中一个应用程序,以便它返回我的数据框中每个用户的位置吗?
    猜你喜欢
    • 2014-09-15
    • 1970-01-01
    • 2020-10-06
    • 2019-09-14
    • 1970-01-01
    • 2019-01-17
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多