r - R中非UTF-8和ASCII字符twitteR包的问题

标签 r twitter utf-8

在之前的一个问题中,我询问了有关使用 R 中的 twitteR 包从 Haaretz Twitter 提要 (@haaretzcom) 下载大量 Twitter 关注者(及其位置、创建日期、关注者数量等)的问题(参见 Work around rate limit for extracting large list of user information using twitteR package in R )。 Twitter 提要有超过 90,000 个关注者,我可以使用下面的代码下载完整的关注者列表。

   require(twitteR)
   require(ROAuth)
   #Loading the Twitter OAuthorization
   load("~/Dropbox/Twitter/my_oauth")

   #Confirming the OAuth
   registerTwitterOAuth(my_oauth)

  # opening list to download
  haaretz_followers<-getUser("haaretzcom")$getFollowerIDs(retryOnRateLimit=9999999)

  for (follower in haaretz_followers){
   Sys.sleep(5)
   haaretz_followers_info<-lookupUsers(haaretz_followers)

   haaretz_followers_full<-twListToDF(haaretz_followers_info)

   #Export data to csv
  write.table(haaretz_followers_full, file = "haaretz_twitter_followers.csv",  sep=",")
 }

该代码用于提取许多用户。但是,每当我点击某个用户时,我都会收到以下错误:
Error in twFromJSON(out) :
RMate stopped at line 51
Error: Malformed response from server, was not JSON.
RMate stopped at line 51
The most likely cause of this error is Twitter returning a character which
can't be properly parsed by R. Generally the only remedy is to wait long
enough for the offending character to disappear from searches (e.g. if
using searchTwitter()).
Calls: twListToDF ... lookupUsers -> lapply -> FUN -> <Anonymous> -> twFromJSON
Execution halted

即使我在 twitteR 包之后加载 RJSONIO 包,我也遇到了这个问题。从做一些研究来看,twitteR 和 RJSONIO 包在解析非 UTF-8 或 ASCII 字符(阿拉伯语等)时似乎存在问题http://lists.hexdump.org/pipermail/twitter-users-hexdump.org/2013-May/000335.html .有没有办法在我拥有的代码中简单地忽略非 UTF-8 或 ASCII 并仍然提取所有关注者信息?任何帮助将非常感激。

最佳答案

有一个包更新 (1.1.7),解决了这个问题。见:https://github.com/geoffjentry/twitteR/blob/master/NEWS

关于r - R中非UTF-8和ASCII字符twitteR包的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16574980/

相关文章:

javascript - 如何通过 Twitter API 在删除推文时收到通知?

unicode - Latex 文档中的 UTF-8 Unicode 错误

php - UTF-8贯穿始终

R(data.table)查找间隔中天数比例最大的日历月

r - R 中 twitteR 的 SSL 证书失败

css - 使用 CallBack 或其他方式突出显示 Shiny DataTable 中的行

php - 提交表单时用 # 和 @replies 标记单词!推特风格?

c# - 在 C# 字符串/字符编码中,GetBytes()、GetString() 和 Convert() 之间有什么区别?

r - 从 glm 系数中提取引用水平

r - 如何将不同的数字格式应用于 R 中的每一行