【发布时间】:2018-03-09 05:20:01
【问题描述】:
我正在尝试通过 R 访问 QuickBooks 在线 API。这是我目前所拥有的:
library(httr)
library(httpuv)
endPoint <- oauth_endpoint(request = NULL,
authorize = "https://appcenter.intuit.com/connect/oauth2",
access = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer")
App <- oauth_app("Untitled",
key = "xxxx",
secret = "xxxxx",
redirect_uri = "http://localhost:1410/")
QBOtoken <- oauth2.0_token(endpoint = endPoint,
app = App,
scope = "com.intuit.quickbooks.accounting",
type = "code",
cache = T)
GET("https://sandbox-quickbooks.api.intuit.com/v3/company/193514718345164/query?query=Select * from Payment", config(token = QBOtoken))
当通过QBOtoken运行上面的代码时,我通过了整个Oauth2.0“跳舞”并得到了响应:
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
但是,当我执行 GET 命令时,它会返回:
Error in self$credentials$access_token :
$ operator is invalid for atomic vectors
生成的.httr-oauth 文件填充了 284 行,每行 32 个字符。这正常吗?
我已经通过 Postman 连接到 API,它会生成一个访问令牌,允许我在我的代码中执行查询,例如 GET 请求。 Intuit Developer 上还有一个 Oauth 2.0 操场。不知何故,在 R 中,我没有获得访问令牌和刷新令牌。
另一个问题是我目前正在尝试连接到开发环境。对于 QuickBooks Online,重定向 URL 可以是开发环境中的 localhost,但如果我想连接到生产公司(我的公司)数据,我将需要一个 https 重定向 URL。这可以通过 R 实现吗?
我对这个项目的最终目标是让脚本每晚自动运行,连接到 API,并将数据 ETL 到关系数据库中以用于报告/分析目的。任何帮助将不胜感激!
【问题讨论】:
-
嘿!你有没有想过这个???做同样的事情。
-
嗨@Super_John,请在下面查看我的回答。这不是很好,自 3 月以来我还没有搞砸过,但它应该能让你朝着正确的方向前进!
标签: r oauth-2.0 postman quickbooks-online httr