【发布时间】:2016-08-23 17:44:25
【问题描述】:
我想用 R 自动将数据上传到 GoogleAnalytics,但找不到方法。
到目前为止,我已经这样做了:
- 根据googleAuthR包获取google auth token:
token <- Authentication$public_fields$token
-
生成上传端点的url:
url.template <- "https://www.googleapis.com/upload/analytics/v3/management/accounts/%1$i/webproperties/%2$s/customDataSources/%3$s/uploads" url <- sprintf(url.template, account.id, web.property.id, data.source) -
使用 httr 包调用 POST:
httr::content_type("text/csv") httr::POST(url = url, body = list(y = httr::upload_file("ga-product-import.csv")), 配置=令牌, 编码=“多部分” )
到目前为止,我收到了 400 条回复。
我也试过这个:
f <- gar_api_generator(url,
"POST",
data_parse_function = function(x) x)
f(the_body = list(y = httr::upload_file("ga-product-import.csv")))
但收到此错误:
错误:没有方法 asJSON S3 类:form_file 错误 the_request$status_code : $ 运算符对原子向量无效
【问题讨论】:
-
如果您运行来自
googleAuthR的示例之一会发生什么? -
@Hack-R 我没有看到任何文件上传的例子,你能给一个链接
-
@Hack-R 我试过
gar_api_generator,但这似乎也不起作用。 -
googleAnalyticsR现在有成本数据导入github.com/MarkEdmondson1234/googleAnalyticsR/blob/master/R/…
标签: r import google-analytics