I am requesting user details to the Facebook Graph API, such as
require(RJSONIO)
response <- RJSONIO::fromJSON("http://graph.facebook.com/?ids=Jack")
print(response)
# $Jack
# id first_name gender last_name locale
# "534213341" "Jack" "male" "Lindamood" "en_US"
# name username
# "Jack Lindamood"
All good.
But then sometime I have an error from the API to handle. Such as this error response (hope nobody will take this username...)
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist: this.username.does.not.exist.because.i.made.it.up",
"type": "OAuthException",
"code": 803
}
}
If I try to parse it with RJSONIO
RJSONIO::fromJSON("http://graph.facebook.com /?ids=this.username.does.not.exist.because.i.made.it.up")
I get
Error in file(con, "r") : cannot open the connection
But then If I first parse the json with RCurl
I get the rjson-formatted error message
require(RCurl)
json <- getURL("http://graph.facebook.com/?ids=this.username.does.not.exist.because.i.made.it.up")
RJSONIO::fromJSON(json)
$error
$error$message
[1] "(#803) Some of the aliases you requested do not exist: this.username.does.not.exist.because.i.made.it.up"
$error$type
[1] "OAuthException"
$error$code
[1] 803
It is possible to manage the error directly with RJSONIO
?