Skip to content

Instantly share code, notes, and snippets.

@sergiospagnuolo
Last active October 23, 2020 16:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergiospagnuolo/f7b5bdd2fc430c791746a39d99319406 to your computer and use it in GitHub Desktop.
Save sergiospagnuolo/f7b5bdd2fc430c791746a39d99319406 to your computer and use it in GitHub Desktop.
Acessando API do Atlas da Notícia via R
# Força o encoding para UTF-8, default do banco de dados
# Colaboração de Sérgio Spagnuolo (sergio@voltdata.info)
# Programa acessar a API do Atlas da Notícia (https://www.atlas.jor.br/)
# É necessário antes se cadastrar, veja como aqui: https://www.atlas.jor.br/plataforma/utilizarAPI/
library(httr)
library(jsonlite)
# Puxa os dados da sua credencial
token = content(
POST(url = "https://api.atlas.jor.br/api/v1/auth/login",
body = list("email" = "email@email.com", "password" = "12345678"),
encode = "json", handle = NULL),
as = "text")
# Parseia o json token retornado no processo acima
token = fromJSON(token)
# Separa apenas o token dentre os 3 itens do json
tk <- token[[1]]
# Retorna a tabela resultante do query desejado
tabela <- fromJSON(content(GET(url = "https://api.atlas.jor.br/api/v1/data/analytic?estado=RO",
add_headers(Authorization = paste("Bearer", tk, sep = " "))),
as = "text"))
View(tabela)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment