我在网上进行了大量搜索,但在使用' twitteR'时仍然无法找到解决以下错误的方法。包装在R:
"Error in twFromJSON(out) :
Error: Malformed response from server, was not JSON.
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())."
运行以下代码后出现:
# Clear the previously used libraries
rm(list=ls())
#Set Working Directory
setwd("C:/Users/toshiba/Google Drive/Programming/Projects/HDS/Shiny/Twitter")
#Load Libraries
library (twitteR)
library (RJSONIO)
library (dismo)
library (maps)
library (ggplot2)
library (XML)
load("twitteR_credentials")
registerTwitterOAuth(twitCred)
##############################Start App########################################
start_date = '2014-10-10'
end_date = toString(as.Date(start_date)+1)
#Search for tweets containing ebola - only goes back 8 days including today
ebolaTweets <- searchTwitter("ebola",
n = 1250,
since=start_date,
until=end_date,
cainfo="cacert.pem")
tweetFrame <- twListToDF(ebolaTweets) # convert to dataframe
是否有可能以某种方式跳过违规的推文而不是打破循环?
非常感谢任何帮助!
答案 0 :(得分:1)
使用current version of twitteR
(1.1.8) on Github(更简单地处理身份验证),我没有问题。
library(devtools)
install_github('twitteR', 'geoffjentry')
library (twitteR)
setup_twitter_oauth(consumer_key='blah', consumer_secret='blah',
access_token='blah', access_secret='blah')
# get keys and tokens from apps.twitter.com
start.date <- '2014-10-10'
end.date <- as.character(as.Date(start_date) + 1)
ebolaTweets <- searchTwitter('ebola', 1250, since=start.date, until=end.date)
ebola <- twListToDF(ebolaTweets)
head(ebola)
# text
# 1 RT @ChillVibessonly: Ebola: I'm in the US broom broom\n\nAmerica: Get out me country
# 2 RT @RubenSanchezTW: #Alucinante TVE usa imágenes de un hospital alemán para ilustrar una info sobre el Carlos III http://t.co/5f5okmsjar ht…
# 3 RT @DanLpda: Dejen de hablar del Ébola, me da miedo
# 4 Realiza Colombia estudios a 3 viajeros por temor a ébola: Pese a no presentar síntomas del virus los pasajeros... http://t.co/C5iJmgoQkI
# 5 Que es eso del ebola? Voy a llorar
# 6 RT @MicaMamonde: ebola no te tenemos miedo http://t.co/osgLmAmFnP
# favorited favoriteCount replyToSN created truncated replyToSID id replyToUID
# 1 FALSE 0 <NA> 2014-10-10 23:59:59 FALSE <NA> 520725464223326209 <NA>
# 2 FALSE 0 <NA> 2014-10-10 23:59:59 FALSE <NA> 520725464185581568 <NA>
# 3 FALSE 0 <NA> 2014-10-10 23:59:59 FALSE <NA> 520725463304785921 <NA>
# 4 FALSE 0 <NA> 2014-10-10 23:59:59 FALSE <NA> 520725463270821889 <NA>
# 5 FALSE 1 <NA> 2014-10-10 23:59:59 FALSE <NA> 520725463120244737 <NA>
# 6 FALSE 0 <NA> 2014-10-10 23:59:59 FALSE <NA> 520725463044734976 <NA>
# statusSource screenName retweetCount
# 1 <a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a> JaMeseKisses 684
# 2 <a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a> patillagrande 2059
# 3 <a href="http://twitter.com" rel="nofollow">Twitter Web Client</a> AriiFranciscovi 2
# 4 <a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a> ColnRos 0
# 5 <a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> ZoeVignieri 0
# 6 <a href="http://twitter.com" rel="nofollow">Twitter Web Client</a> felicitasalbano 10
# isRetweet retweeted longitude latitude
# 1 TRUE FALSE <NA> <NA>
# 2 TRUE FALSE <NA> <NA>
# 3 TRUE FALSE <NA> <NA>
# 4 FALSE FALSE <NA> <NA>
# 5 FALSE FALSE <NA> <NA>
# 6 TRUE FALSE <NA> <NA>