How to use OAuth at XING with R

那年仲夏 提交于 2019-12-05 13:39:40

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?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!