如何在R中获取Saber API的令牌类似于此帖子中的python:How do I perform oauth2 for Sabre Dev Network using python?
据我了解,我需要使用OAuth2验证流程。对于R,我找到了httr
包含此函数的oauth2.0_token
here,但我无法输入正确的参数来获取令牌。
到目前为止我的代码:
library(base64enc)
library(base64)
clientID <- "V1:userid:group:domain" #Example clientID
clientIDRaw <- charToRaw(clientID)
clientIDEnc <- base64encode(clientIDRaw)
password <- "12345" #Example password
passwordRaw <- charToRaw(password)
passwordEnc<- base64encode(passwordRaw)
combined <- paste(clientIDEnc, ":", passwordEnc, sep="")
combinedRaw <- charToRaw(combined)
combinedEnc <- base64encode(combinedRaw)
使用combinedEnc
变量,我应该能够检索我的令牌吗?
答案 0 :(得分:0)
我不知道R,所以我不知道convertToRaw究竟做了什么,但我在下面的链接中测试了下面的代码,它起作用了:https://www.rdocumentation.org/packages/caTools/versions/1.17.1/topics/base64encode%20%26%20base64decode
user = "V1:userid:group:domain"
print(user)
userEnc = base64encode(user)
print(userEnc)
password = "password"
print(password)
passwordEnc = base64encode(password)
print(passwordEnc)
credentials = paste(userEnc, passwordEnc, sep=":")
print(credentials)
credentialsEnc = base64encode(credentials)
print(credentialsEnc)
如果这些步骤按预期工作,那么请关注Thomas的评论(特别是Postman中的测试),或者添加您获得的实际错误。
答案 1 :(得分:0)
根据您在评论中的说明,这是您正在寻找的请求
curl -X POST \
https://api.sabre.com/v2/auth/token \
-H 'Accept: */*' \
-H 'Authorization: Basic
Your combinedEnc' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Postman-Token: XXX-edcb-4b2a-aa3d-XXXX' \
-d grant_type=client_credentials