skardhamar / rga

R Google Analytics
187 stars 90 forks source link

Auth Error: Error in fromJSON(raw.data) : STRING_ELT() can only be applied to a 'character vector', not a 'raw' #23

Open WillemPaling opened 10 years ago

WillemPaling commented 10 years ago

I've recently started getting this issue when I try to authenticate.

traceback()
5: .Call("fromJSON", json_str, unexpected.escape, PACKAGE = "rjson")
4: fromJSON(raw.data)
3: .rga.authenticate(client.id = client.id, client.secret = client.secret, 
       code = code, redirect.uri = redirect.uri)
2: .rga.getToken(client.id, client.secret)
1: rga.open(instance = "ga", client.id = "willems-client-id", 
       client.secret = "willems-secret")

Any ideas? I'll fork and try to fix it...but if anyone else is having this problem and know what it might be related to, let me know.

Not sure if it's due to having too many JSON libraries loaded. With jsonlite, there's 3 of them now.

WillemPaling commented 10 years ago

I've fixed it in my fork by changing auth.R

token.data <- fromJSON(raw.data);

becomes

  if(class(raw.data)=="raw") {
      token.data <- fromJSON(rawToChar(raw.data));
    } else {
      token.data <- fromJSON(raw.data);
    }

Does that make sense? If it does, let me know and I'll submit a pull request.

WillemPaling commented 10 years ago

Using this at home, I got a different error (Bad Request again). I resolved this by switching post requests to use HTTR instead of using RCurl directly.

The above code is not necessary, because HTTR always returns a request object, not a raw or a char.