How to use request header with API data requests?

I am trying to find a way to connect to the Appannie API using R using the httr package (having no experience with the API at all). The API requires you to include the request header. Quote from the appannie website: Register an App Annie account and create an API key. Add this key to your request header as follows:
Authorization: citation by a medium

I wrote code that looks like

query <- "http://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 811b..."))

the http_status (getdata) command shows me a “client error: (401) Unauthorized” someone can help me with this, what am I doing wrong?

+4
source share
1 answer

. 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&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"

"" , 401. 1000 .

http/https , http 2014-04-01, https.

+6

Source: https://habr.com/ru/post/1533581/


All Articles