httr

R: Emulating a complex form with httr

对着背影说爱祢 提交于 2019-12-04 23:42:09
问题 I am trying to get the results of that form with httr . Having looked the form results, I tried the following: library(httr) library(stringr) r = str_c("http://www.memoiredeshommes.sga.defense.gouv.fr/fr/arkotheque/", "client/mdh/base_morts_pour_la_france_premiere_guerre/index.php") q = list( "action" = 1, "todo" = "rechercher", "le_id" = "", "multisite" = "", "r_c_nom" = "mo", "r_c_nom_like" = 1, "r_c_prenom" = "", "r_c_prenom_like" = 1, "r_c_naissance_jour_mois_annee_jj_debut" = "", "r_c

Upload a file over 2.15 GB in R

人盡茶涼 提交于 2019-12-04 22:13:41
I've got a manual process where I'm uploading 5-6 GB file to a web server via curl: curl -X POST --data-binary @myfile.csv http://myserver::port/path/to/api This process works fine, but I'd love to automate it using R. The problem is, I either don't know what I'm doing, or the R libraries for curl don't know how to handle files bigger than ~2GB: library(RCurl) postForm( "http://myserver::port/path/to/api", file = fileUpload( filename = path.expand("myfile.csv"), contentType = "text/csv" ),.encoding="utf-8") Yeilds Error: Internal Server Error httr doesn't work either: library(httr) POST( url =

How correctly use request header with API data requests?

允我心安 提交于 2019-12-04 21:43:31
问题 I'm trying to find the way to connect to Appannie's API with R using the httr package (have no experience with API connection at all). The API requires to include the request header Citation from appannie's site: Register an App Annie account and generate an API key. Add this key to your request header as follows: Authorization: Bearer '' citation over I wrote the code which looks like this query <- "http://api.appannie.com/v1/accounts/1000/sales?break_down=application+dat &start_date=2012-01

Accessing Spotify API for Multiple Artists in R

99封情书 提交于 2019-12-04 19:20:33
I have created a Client ID and Secret Key in Spotify's developer app section. I am referencing this document and want to extend this by choosing multiple artists. https://www.r-bloggers.com/the-eurovision-2016-song-contest-in-an-r-shiny-app/ In this example, they are only choosing 1 artist ID but there are some holes to this, 1) How do you obtain the artist name rather than the artist ID because I can't find a glossary key anywhere for the artist ID? 2) How do you choose multiple artists rather than just one. So for example, how do I choose Frank Sinatra and Elvis Presley? Code is below:

Census Batch Geocoding API with source addresses in data frame (not CSV) in R

假装没事ソ 提交于 2019-12-04 18:10:51
I am attempting to utilize the Census Bureau's batch geocoder ( http://geocoding.geo.census.gov/geocoder/Geocoding_Services_API.pdf ) with R. The input addresses are in a data frame, not a CSV. As the addresses are an intermediate step, I do not want to write them to a CSV. I have read several postings on stackoverflow. Hadley's solution ( Posting to and Receiving data from API using httr in R ) illustrates how to upload an existing CSV file. MrFlick's solution ( Uploading a csv to an api in R ) seems close to what I want but uses a string, not a data frame. Here's what I have in the way of

R httr POST of JSON returns status 400

霸气de小男生 提交于 2019-12-04 18:08:49
I'm working on a few functions to get data from StatBank Denmark, and their API . They have made a console to test JSON calls and I know the basic_request I parse to JSON in the function dst_get_data works, as I have tested it in the console. I get a "status 400" error and an error message that says that I should "supply object when posting". The code below should make reproducible example. It is the third function (dst_get_data) where I am stuck. dst_meta <- function(table, ..., lang = "en"){ require(jsonlite) require(httr) dkstat_url <- "http://api.statbank.dk/v1/tableinfo" params <- list(

How to post within a rvest html_session?

萝らか妹 提交于 2019-12-04 18:01:54
How can i post "within" a html session? So after i opened a session via a <- rvest::html_session(url) I tried: library(httr) POST(path, add_headers(setNames(as.character(headers(a)), names(headers(a)))), set_cookies(setNames(cookies(a)$value, cookies(a)$name)), body = list(...), encode = "json") But this handles my request as I were not logged in. Any suggestions? I am looking for something like POST(session, path, body, ...) Ok, after some digging into it i solved it by using: x %>% rvest:::request_POST(url, config(referer = x$url), user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4)

Post request using cookies with cURL, RCurl and httr

白昼怎懂夜的黑 提交于 2019-12-04 14:04:40
问题 In Windows cURL I can post a web request similar to this: curl --dump-header cook.txt ^ --data "RURL=http=//www.example.com/r&user=bob&password=hello" ^ --user-agent "Mozilla/5.0" ^ http://www.example.com/login With type cook.txt I get a response similar to this: HTTP/1.1 302 Found Date: Thu, ****** Server: Microsoft-IIS/6.0 SERVER: ****** X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Location: ****** Set-Cookie: Cookie1=; domain=******; expires=****** ****** ****** ****** Cache-Control:

Handling error response to empty webpage from read_html

两盒软妹~` 提交于 2019-12-04 13:31:15
Trying to scrape a web page title but running into a problem with a website called "tweg.com" library(httr) library(rvest) page.url <- "tweg.com" page.get <- GET(page.url) # from httr pg <- read_html(page.get) # from rvest page.title <- html_nodes(pg, "title") %>% html_text() # from rvest read_html stops with an error message: "Error: Failed to parse text". Looking into page.get$content, find that it is empty (raw(0)). Certainly, can write a simple check to take this into account and avoid parsing using read_html. However, feel that a more elegant solution would be to get something back from

Using an API to calculate distance between two airports (two columns) within R?

流过昼夜 提交于 2019-12-04 12:17:52
问题 I was wondering whether there was a way to compare airport distances(IATA codes). There are some scripts but not is using R. So I tried that with with the API: developer.aero Example data: library(curl) # for curl post departure <- c("DRS","TXL","STR","DUS","LEJ","FKB","LNZ") arrival <- c("FKB","HER","BOJ","FUE","PMI","AYT","FUE") flyID <- c(1,2,3,4,5,6,7) df <- data.frame(departure,arrival,flyID) departure arrival flyID 1 DRS FKB 1 2 TXL HER 2 3 STR BOJ 3 4 DUS FUE 4 5 LEJ PMI 5 6 FKB AYT 6