【问题标题】:Connecting to LinkedIn via ouath and R通过 ouath 和 R 连接到 LinkedIn
【发布时间】:2015-01-23 17:29:15
【问题描述】:

已使用 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")

【问题讨论】:

    标签: r oauth oauth-2.0 linkedin


    【解决方案1】:

    请改用httr。 Hadley 在他的包中有一个例子: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)
    

    【讨论】:

    • 谢谢!似乎引导我朝着正确的方向前进,但是,Token2.0 给了我一个问题。我已经安装了 R6 包和库;但收到 Token2.0 的错误消息 - 找不到“Token2.0”。浏览 Hadley W. 的 github 并四处搜索,但没有找到解决此问题的方法。
    • @hnreddy Token2.0 应该在httr 中,请参阅httr::Token2.0。也许您需要升级httr?我有版本0.5.0.900
    • 谢谢 - 这可能是问题所在。使用 packageVersion("httr"),我返回 '0.5'。所以这肯定和你的 0.5.0.900 不同,但是,当我去 CRAN (cran.r-project.org) 时,最新版本也是 '0.5'。我想我需要弄清楚如何从 Hadley 的 github 中提取 httr? (github.com/hadley/httr)?
    • 是的,刚刚检查过,看起来Token2.00.5.0 相比略有变化。从 Github 安装,例如 devtools::install_github("hadley/httr")
    • 好的 - 谢谢。沿着路径开始并安装了 devtools 包和库,但是使用的是 Mac,所以需要弄清楚如何让 make 工作......让我弄清楚这一点并祈祷它有效。
    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-13
    • 1970-01-01
    相关资源
    最近更新 更多