我正试图找到使用httr包连接到Appannie的API的方法(根本没有API连接的经验).API要求在appannie的网站上包含请求标题Citation:
注册App Annie帐户并生成API密钥.将此密钥添加到您的请求标头中,如下所示:
授权:Bearer''引用
我编写了看起来像这样的代码
query <- "http://api.appannie.com/v1/accounts/1000/sales?break_down=application+dat
&start_date=2012-01-01
&end_date=2012-02-01
¤cy=USD
&countries=US
&page_index=1"
getdata<-GET(url=query, add_headers("Authorization: bearer 811b..."))
Run Code Online (Sandbox Code Playgroud)
命令http_status(getdata)显示"客户端错误:(401)未经授权"有人可以帮助我,我做错了什么?
您没有正确指定标题.add_headers(...)需要一个命名列表.
library(httr) # for GET(...)
library(rjson) # for fromJSON(...)
query <- "https://api.appannie.com/v1/accounts/1000/sales?break_down=application+dat&start_date=2012-01-01&end_date=2012-02-01¤cy=USD&countries=US&page_index=1"
getdata<-GET(url=query, add_headers(Authorization="bearer <your api key>"))
fromJSON(content(getdata,type="text"))
# $code
# [1] 403
#
# $error
# [1] "Invalid connection account"
Run Code Online (Sandbox Code Playgroud)
从"我没有得到401错误"的意义上说这"有效".在我的情况下,帐户1000不存在.
关于评论中的http/https问题,http已经解除,并且自2014-04-01起将不再被接受,因此您也可以开始使用https.
| 归档时间: |
|
| 查看次数: |
7310 次 |
| 最近记录: |