hnreddy
hnreddy

Reputation: 63

Connecting to LinkedIn via ouath and R

Have successfully connected to Twitter using R and trying to leverage that code to connect to LinkedIn, but not quite able to make it work.

I think the code is close, but somehow the last step is returning an error.

Currently, I am able to get LinkedIn to return a token right after the handshake, but when I query it in the browser, I get an error from linkedIn saying that a client_id is required.

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

The R code to create the OAuth file is below with the keys provided by LinkedIn redacted out.

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")

Upvotes: 1

Views: 980

Answers (1)

sckott
sckott

Reputation: 5893

Use httr instead. Hadley has an example in his package: https://github.com/hadley/httr/blob/master/demo/oauth2-linkedin.r

Here's example

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)

Upvotes: 4

Related Questions