通过oauth和R连接到LinkedIn

时间:2014-11-25 15:59:42

标签: r oauth oauth-2.0 linkedin

使用R成功连接到Twitter并尝试利用该代码连接到LinkedIn,但无法使其正常工作。

我认为代码很接近,但不知何故最后一步是返回错误。

目前,我能够在握手后立即让LinkedIn返回令牌,但是当我在浏览器中查询它时,我从linkedIn得到一个错误,说需要client_id。

https://www.linkedin.com/uas/oauth2/authorization?oauth_token=< ...>

创建OAuth文件的R代码如下所示,LinkedIn提供的密钥已完成。

rm(list=ls())

library(ROAuth)

reqURL <- "https://api.linkedin.com/uas/oauth/requestToken"
accessURL <- "https://api.linkedin.com/uas/oauth2/accessToken"
authURL <- "https://www.linkedin.com/uas/oauth2/authorization"
consumerKey <- "<...>"
consumerSecret <- "<...>"
#oAuthKey <- "<...>"
#oAuthSecret <- "<...>"

linkedInCred <- OAuthFactory$new(consumerKey=consumerKey,
                              consumerSecret=consumerSecret,
                              requestURL=reqURL,
                              accessURL=accessURL,
                              authURL=authURL)

linkedInCred$handshake()

credentials$OAuthRequest(testURL, "GET")


save(linkedInCred, file="credentials.RData")

1 个答案:

答案 0 :(得分:2)

请改用httr。哈德利在他的包裹中有一个例子:https://github.com/hadley/httr/blob/master/demo/oauth2-linkedin.r

这里的例子

library("httr")
myapp <- oauth_app(appname = "scottsapp", key = "<key>", secret = "<secret>")
TokenLinkedIn <- R6::R6Class("TokenLinkedIn", inherit = Token2.0, list(
  sign = function(method, url) {
    url <- parse_url(url)
    url$query$oauth2_access_token <- self$credentials$access_token
    list(url = build_url(url), config = config())
  }
))
token <- TokenLinkedIn$new(endpoint = oauth_endpoints("linkedin"), app = myapp)