我想从R访问domain.com.au(包含澳大利亚房地产列表的网站)的api。
我一直在尝试通过客户端凭据获取访问令牌,如本网站https://developer.domain.com.au/docs/authorisation/client-credentials-grant所述。它说:“使用client_id和client_secret以及所需的作用域列表向https://auth.domain.com.au/v1/connect/token端点发出POST请求。请参阅API参考以获取每个端点所需的作用域列表。尝试使用计划中未包含的范围将导致400 invalid_scope错误。必须使用基本身份验证对该请求进行身份验证,并且client_id和client_secret分别与用户名和密码相对应。“
# Install and/or load packages
packageList <- c("httr", "jsonlite")
invisible(GetPackages(packageList))
# Endpoint as instructed on https://developer.domain.com.au/docs/
# authorisation/client-credentials-grant.
domain_endpoint <- oauth_endpoint(
authorize = NULL,
access = "https://auth.domain.com.au/v1/connect/token"
)
# Create application on https://developer.domain.com.au/applications/.
# Choose "Innovation" plan for "Properties & Locations" package.
# Replace clientID and secret in the code below.
domain_app <- oauth_app(
appname = "application1",
key = "clientID",
secret = "secret"
)
# Request token as instructed on https://developer.domain.com.au/docs/
# authorisation/client-credentials-grant.
# Use scope from https://developer.domain.com.au/docs/
# endpoints/salesresults/salesresults_head
domain_token <- oauth2.0_token(
endpoint = domain_endpoint,
app = domain_app,
client_credentials = T,
scope = c("api_salesresults_read"),
use_basic_auth = T
)`
我希望收到访问令牌,但是却收到消息“ oauth2.0_access_token中的错误(端点,应用程序,代码=代码,user_params = user_params 、:错误的请求(HTTP 400)。无法获取访问令牌。”