我正在尝试使用 r 和 httr 访问domain.com.au api。我可以使用 API 密钥来实现此目的,但不能使用 OAuth2
该文档表明:
通过客户端凭证获取访问令牌 使用您的 client_id 和 client_secret 以及您需要的范围列表向https://auth.domain.com.au/v1/connect/token端点发出 POST 请求。请参阅 API 参考,了解每个端点所需的范围列表。尝试使用计划中未包含的范围将导致 400 invalid_scope 错误。该请求必须使用基本身份验证进行身份验证,其中 client_id 和 client_secret 分别对应于用户名和密码。
https://developer.domain.com.au/docs/v2/authentication/oauth/client-credentials-grant
卷曲的实现很简单:
curl -X POST -u 'clientid:secret' -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=client_credentials&scope=api_listings_read%20api_agencies_read' 'https://auth.domain.com.au/v1/connect/token'
Run Code Online (Sandbox Code Playgroud)
它返回令牌而不进行任何重定向。
但是,我无法将其转换为等效的 httr POST 请求来获取令牌。我目前拥有的是:
oep <- oauth_endpoint(base_url = "https://auth.domain.com.au/v1/connect/token",
request = NULL,
access = "access_token" )
myapp <- oauth_app("domain",
key = "client_id_here",
# The secret isn't secrete. A user still has to authenticate when redirected.
secret = …Run Code Online (Sandbox Code Playgroud) 以下代码是否表示遍历 R 的行data.table并将在每一行找到的值传递给函数的首选过程?或者有没有更高效的方法来做到这一点?
library(data.table)
set.seed(2)
n <- 100
b <- c(0.5, 1.5, -1)
phi <- 0.8
X <- cbind(1, matrix(rnorm(n*2, 0, 1), ncol = 2))
y <- X %*% matrix(b, ncol = 1) + rnorm(n, 0, phi)
d <- data.table(y, X)
setnames(d, c("y", "x0", "x1", "x2"))
logpost <- function(d, b1, b2, b3, phi, mub = 1, taub = 10, a = 0.5, z = 0.7){
N <- nrow(d)
mu <- b1 + b2 * d$x1 + b3 * …Run Code Online (Sandbox Code Playgroud)