我试图从R中直接连接到BI工具的API。API文档列出下面的curl命令以获得身份验证令牌:
curl -X POST -H "Content-Type: application/json" -d
'{
"email": "your@email.com",
"password": "your_password"
}'
https://app.datorama.com/services/auth/authenticate此外,下面是一个可用于查询数据的JSON查询示例:
{
"brandId": "9999",
"dateRange": "CUSTOM",
"startDate": "2016-01-01",
"endDate": "2016-12-31",
"measurements": [
{
"name": "Impressions"
}
],
"dimensions": [
"Month"
],
"groupDimensionFilters": [],
"stringDimensionFilters": [],
"stringDimensionFiltersOperator": "AND",
"numberDimensionFiltersOperator": "AND",
"numberMeasurementFilter": [],
"sortBy": "Month",
"sortOrder": "DESC",
"topResults": "50",
"groupOthers": true,
"topPerDimension": true,
"totalDimensions": []
}我正在尝试将上面的curl命令转换为R,以便获得所需的身份验证令牌;2)通过上面的JSON脚本查询数据。
到目前为止,我尝试使用httr库,如下所示:
library(httr)
r <- POST('https://app.datorama.com/services/auth/authenticate',
body = list(
brandId = "9999",
dateRange = "CUSTOM",
measurements = list(name="Impressions"),
dimensions = list(name="Month"),
startDate = "2016-01-01",
endDate = "2016-12-31"
),
encode = "json",
authenticate("username", "password"))都没有用。
API文档位于一个受密码保护的页面后面,因此我无法链接它。如果需要更多的资料,请告诉我。
发布于 2016-07-25 14:13:56
赫布姆斯特尔是完全正确的!您应该生成两个api调用,第一个是对用户进行身份验证,第二个是查询数据。
下面是一个使用R.提供的Datorama查询API的完整示例,请随时与Datorama支持联系,了解任何其他问题。
library(httr)
res <- POST("https://app.datorama.com/services/auth/authenticate",
body=list(email="your@email.com",
password="your_password"),
encode="json")
token <- content(res)$token
res_query <- POST(paste("https://app.datorama.com/services/query/execQuery?token=",token, sep=""),
body = list(
brandId = "9999",
dateRange = "CUSTOM",
measurements = list(list(name = "Impressions")),
dimensions = list("Month"),
startDate = "2016-01-01",
endDate = "2016-12-31"
),
encode = "json")
cat(content(res_query, "text"), "\n")发布于 2016-07-24 14:42:52
我无法访问他们的API,如果他们有一个免费的层,我会为这个服务编写一个小包装pkg。话虽如此,
curl -X POST \
-H "Content-Type: application/json" \
-d '{ "email": "your@email.com",
"password": "your_password" }'翻译为:
library(httr)
res <- POST("https://app.datorama.com/services/auth/authenticate",
body=list(email="your@email.com",
password="your_password"),
encode="json")他们在网上也没有免费的API文档,但我假设它会用某种类型的authorization_token和编码的字符串发送回JSON响应。
然后--很可能--需要在随后的每个API调用中传递这个结果(并且可能会有一个超时,需要重新设置初始的auth )。
authenticate()用于HTTP,而不是用于这种类型的in/REST。
除了使用令牌auth之外,您的实际API调用看起来还不错。
https://stackoverflow.com/questions/38549305
复制相似问题