I\'m getting the following error message for this code intended to read Instagram posts into r. Other code is successfully reading in the first 20 posts, but Instagram want
I can reproduce your problem by extending your code snippet with code that extracts next_url
from the pagination
object in the JSON response returned by Instagram.
When using rjson::fromJSON
to parse the JSON response I get errors like
Error in rjson::fromJSON(js) : unexpected character: i
However, using RJSONIO::fromJSON
for parsing the exact same string works just fine! Also the string validates as correct JSON with online JSON validators.
This strongly points to a bug in rjson::fromJSON
. You may want to use the RJSONIO package instead for now.
Unfortunately these Instagram replies are quite large. I'll see if I can strip down the JSON output to something manageable so I can post details here. (I'm trying to avoid having to link to data on an external site.)
I suspect an encoding issue with Instagram user names.
Using RJSONSIO and Rcpp, you should be able to get what you want from:
media1 <- fromJSON(getURL(paste(url,token,sep="")
next_url <- media1$pagination[1]
media2 <- fromJSON(getURL(next_url))
No need to specify additional arguments in fromJSON()