Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. library(httr)
  2. library(base64enc)
  3. library(jsonlite)
  4.  
  5. url<-"https://api.ebay.com/identity/v1/oauth2/token"
  6. clientID<-"****-testapp-******-*****"
  7. clientSecret<-"PRD-8********-***-***-****-****"
  8. base64encode(paste(clientID,clientSecret,sep = ":"))
  9.  
  10.  
  11. request_body <- data.frame(
  12. code="v%5E1.1%23i%5E1%23I%5E3%23r%5E1%23p%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
  13. grant_type="authorization_code",
  14. redirect_uri="*****-*****-testap-******"
  15. )
  16.  
  17.  
  18. ##Approach 1##
  19. result <- POST(url=url,
  20. body = request_body,
  21. add_headers(.headers = c("Content-Type"="application/x-www-form-urlencoded",
  22. "Authorization"="Basic ******************...*****YQ=="
  23. )))
  24. Output <- content(result)
  25.  
  26. ##Approach 2##
  27. request_body_json <- toJSON(list(documents = request_body), auto_unbox = TRUE)
  28.  
  29. result <- POST(url=url,
  30. body = request_body_json,
  31. add_headers(.headers = c("Content-Type"="application/x-www-form-urlencoded",
  32. "Authorization"="Basic ******************...*****YQ=="
  33. )))
  34.  
  35. Output <- content(result)
  36. result
  37. Output <- content(result)
  38. Output
  39.  
  40. > result <- POST(url=url,
  41. + body = request_body,
  42. + add_headers(.headers = c("Content-Type"="application/x-www-form-urlencoded",
  43. + "Authorization"="Basic RGVubmlzRXUtdGVzdGFwcC1QUkQtMzhlMzVjNTM1LWFjNzdjODE5OlBSRC04ZTM1YzUzNTFiNzktN2UwMS00YzMxLWE0YTQtM2U5YQ=="
  44. + )))
  45. Fehler in curl::handle_setform(handle, .list = req$fields) :
  46. Insupported value type for form field 'code'.
  47.  
  48. > Output <- content(result)
  49. > Output
  50. $error
  51. [1] "unsupported_grant_type"
  52.  
  53. $error_description
  54. [1] "grant type in request is not supported by the authorization server"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement