Skip to content

Commit

Permalink
update linkedin example (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Poh Zi How authored and hadley committed Jun 5, 2018
1 parent 6b2dadc commit 976289a
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions demo/oauth2-linkedin.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ library(httr)

# 1. Find OAuth settings for linkedin:
# https://developer.linkedin.com/documents/linkedins-oauth-details
oauth_endpoints("linkedin")
endpoints <- oauth_endpoints("linkedin")

# 2. Register an application at https://www.linkedin.com/secure/developer
# Make sure to register http://localhost:1410/ as an "OAuth 2.0 Redirect URL".
Expand All @@ -14,29 +14,7 @@ myapp <- oauth_app("linkedin",
secret = "n7vBr3lokGOCDKCd")

# 3. Get OAuth credentials
# LinkedIn doesn't implement OAuth 2.0 standard
# (http://tools.ietf.org/html/rfc6750#section-2) so we extend the Token2.0
# ref class to implement a custom sign method.
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
request(url = build_url(url))
},
can_refresh = function() {
TRUE
},
refresh = function() {
self$credentials <- init_oauth2.0(self$endpoint, self$app,
scope = self$params$scope, type = self$params$type,
use_oob = self$params$use_oob)
}
))
token <- TokenLinkedIn$new(
endpoint = oauth_endpoints("linkedin"),
app = myapp,
params = list(use_oob = FALSE, scope = NULL, type = NULL)
)
token <- oauth2.0_token(endpoints, myapp)

# 4. Use API
req <- GET("https://api.linkedin.com/v1/people/~", config(token = token))
Expand Down

0 comments on commit 976289a

Please sign in to comment.