How correctly use request header with API data requests?

一曲冷凌霜 提交于 2019-12-03 14:06:26

You are not specifying the header correctly. add_headers(...) requires a named list.

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&currency=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"

This "works" in the sense that I don't get the 401 error. In my case the account 1000 does not exist.

Regarding the http/https issue from the comment, http is despreciated and will no longer be accepted as of 2014-04-01, so you might as well start using https.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!