4

I'm trying to authenticate to the XING API (api.xing.com) using ROAuth (v0.9.2).

library(package="RCurl")
library(package="ROAuth")

site <- "https://api.xing.com"
requestTokenPath <- "/v1/request_token"
accessTokenPath <- "/v1/access_token"
authorizePath <- "/v1/authorize"

consumerKey <- "***********"    # blank key for posting
consumerSecret <- "********"    # blank key for posting

requestURL <- paste(site, requestTokenPath, sep="")
accessURL <- paste(site, accessTokenPath, sep="")
authURL <- paste(site, authorizePath, sep="")

credentials <- OAuthFactory$new(consumerKey=consumerKey,
    consumerSecret=consumerSecret,
    requestURL=requestURL,
    accessURL=accessURL,
    authURL=authURL,
    needsVerifier=TRUE)

credentials$handshake(ssl.verifypeer=FALSE)  # skip ssl verification for testing, this is passed through to RCurl

Output:

Error in credentials$handshake(ssl.verifypeer = FALSE) : 
  Invalid response from site, please check your consumerKey and consumerSecret and try again.

I double checked my keys and the URLs, so I'm pretty sure that's not the cause of the error.

  1. Can anybody tell me what I'm doing wrong?
  2. Is there a way to extract the server requests and responses for error analysis?

Thanks, Chris

christoph
  • 76
  • 1
  • 4
  • let me know if the below answer worked... – h.l.m Jan 21 '13 at 10:11
  • sure, i think next week i will get back to this. – christoph Jan 22 '13 at 12:19
  • Did you eventually get it working? I'm trying exactly the same, but during handshake I always get a "Authorization Required". Not sure what's happening here, but the API seems to be unstable at the moment. – Alexander Janssen Aug 28 '14 at 09:44
  • Sorry for answering late. It didn't work. The best I got was a `Error in init_oauth1.0(endpoint, app, permission = params$permission) : server error: (504) Gateway Timeout` – christoph Aug 29 '14 at 15:16

1 Answers1

3

I would recommend using the httr package by Hadley Wickham, as I have found it to be particularly helpful when dealing with APIs. And don't forget to CAREFULLY read all relevant documentation...

it looks like XING uses OAuth v1 so look at relevant httr documentation for that

I'm not sure if you already know this...but it's kinda a two stage process...

first you send your consumer key and secret to XING which will return to you a token.

then with all three of:

1) consumer key, 2) consumer secret and 3) the token just provided

can you access all the API calls that XING have set up...you will probably need XML to interpret the responses efficiently though.

not sure if this will work but something along the lines of:

require(httr)
xing.app <- oauth_app("xing",key="xxxxxxxxxx", secret="xxxxxxxxxxxxxxx")
xing.urls <- oauth_endpoint(NULL, "authorize", "access_token",base_url = "https://api.xing.com/v1/")
xing.token <- oauth1.0_token(xing.urls, xing.app)
xing.token

that token in xing.token is for that unique key, and secret combination, i.e. that user...but once you have it...you don't need to keep requesting it...you can store it in your .Rprofile file or something...and then refer to it as an option in your GET or POST commands.

user.signature <- sign_oauth1.0(xing.app, token = token.string.from.xing.token, token_secret = token.secret.from.xing.token)

# so I think as an example you can have this...
id <- "yyyyyyy"
GET(url= paste0("https://api.xing.com/v1/users/",id), config=user.signature)

hope that helps....there may be a few errors in the code as this isn't tested as I don't have your consumer key or secret. I haven't fully read the documentation but I don't think its too far off...please feel free to comeback with corrections...when you actually test it...

out of curiosity...what are you using the API for?

h.l.m
  • 13,015
  • 22
  • 82
  • 169
  • 1
    Does your proposed solution still work? I get the error `Error in handle_url(handle, url, ...) : Must specify at least one of url or handle` when trying your code snippet. – majom Jul 13 '16 at 15:54
  • 1
    @majom: FWIW, set `base_url = "https://api.xing.com/v1"` and `request = "request_token"` instead of `NULL` within `oauth_endpoint`. Now, it should work again. – lukeA Sep 25 '17 at 17:38