Last active
October 23, 2020 16:53
-
-
Save sergiospagnuolo/f7b5bdd2fc430c791746a39d99319406 to your computer and use it in GitHub Desktop.
Acessando API do Atlas da Notícia via R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Força o encoding para UTF-8, default do banco de dados | |
# Colaboração de Sérgio Spagnuolo ([email protected]) | |
# 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 protected]", "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