Unexpected character json error in r

前端 未结 2 1965
清歌不尽
清歌不尽 2020-12-18 05:50

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

相关标签:
2条回答
  • 2020-12-18 06:35

    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.

    0 讨论(0)
  • 2020-12-18 06:47

    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()

    0 讨论(0)
提交回复
热议问题