httr

How can I send a GET request without waiting for the response

↘锁芯ラ 提交于 2019-12-06 15:22:07
I am trying to run a GET request inside a shinyApp, but I don't want to wait for the response as it would take quite a long time to process and I dont need really need the response inside the shinyApp, although a status code would be nice, but it is not obligatory. Or is there maybe a function, that sends an async request? Like wrapping the whole GET inside a future/promise? Currently I have this observeEvent in my shinyApp: observeEvent(input$import, { httr::GET(url = "https://someurl/that/takes/a/long/time") }) Is the curl_fetch_multi from the curl package suited for that task? Here is a way

How to convert an HTML R object to character?

随声附和 提交于 2019-12-06 13:36:58
Here's my reproducible example: library(rvest) page <- html("http://google.com") class(page) page > as.character(page) Error in as.vector(x, "character") : cannot coerce type 'externalptr' to vector of type 'character' How can I convert page from an html class to a character vector so I can store it somewhere? The html functions like html_text or html_attr don't give me the whole source. I would like to store it so I can later re-load it with html(). Thanks. To save directly to a text file: capture.output(page, file="file.html") To store as a string: htmltxt <- paste(capture.output(page, file

R httr POST of JSON returns status 400

妖精的绣舞 提交于 2019-12-06 10:17:22
问题 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"){

415 code using httr and RCurl, but not just curl

笑着哭i 提交于 2019-12-06 05:15:30
I'm trying to write a function that handles some of the authentication for Spotify's API. I can get it to work with a fairly simple curl command, but when I try to use httr or RCurl, I get 415 Unsupported Media Type responses. I'm somewhat at a loss at this point. I've gotten POST() , and GET() to work with this API already, but this endpoint is not working. Using httr : response <- POST('https://accounts.spotify.com/api/token', accept_json(), add_headers('Authorization'=paste('Basic',base64(paste(client_id,':',client_secret)),sep=' ')), body=list(grant_type='client_credentials'), encode='json

Retrieving cached oauth token with packages httr, twitteR, and streamR

拈花ヽ惹草 提交于 2019-12-06 02:55:41
问题 The only way I've found to get myself authenticated with the twitter API is the following: library(twitteR) setup_twitter_oauth(consumer_key = "a", consumer_secret = "b", access_token = "c", access_secret = "d") After running this, I can use all functions in twitteR just fine. However, I would also like to use the streamR package, which needs the token as an OAuth object: filterStream("tweets.json", track = c("Obama", "Biden"), timeout = 20, oauth=my_oauth) From what I gather, the setup

Downloading a file after login using a https URL

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 18:51:31
I am trying to download an excel file, which I have the link to, but I am required to log in to the page before I can download the file. I have successfully passed the login page with rvest, rcurl and httr, but I am having an extremely difficult time downloading the file after I have logged in. url <- "https://website.com/console/login.do" download_url <- "https://website.com/file.xls" session <- html_session(url) form <- html_form(session)[[1]] filled_form <- set_values(form, userid = user, password = pass) ## Save main page url main_page <- submit_form(session, filled_form) download.file

Get response header

本小妞迷上赌 提交于 2019-12-05 08:41:06
I would like to get response headers from GET or POST. My example is: library(httr) library(RCurl) url<-'http://www.omegahat.org/RCurl/philosophy.html' doc<-GET(url) names(doc) [1] "url" "handle" "status_code" "headers" "cookies" "content" "times" "config" but there is no response headers, only request headers. Result shoud be something like this: Connection:Keep-Alive Date:Mon, 11 Feb 2013 20:21:56 GMT ETag:"126a001-e33d-4c12cf2702440" Keep-Alive:timeout=15, max=100 Server:Apache/2.2.14 (Ubuntu) Vary:Accept-Encoding Can I do this with R and httr/RCurl packages or R is not enough for this kind

Login to .NET site using R

柔情痞子 提交于 2019-12-05 05:44:59
I am trying to login with my credentials to a .NET site but unable to get it working. My code is inspired from the below thread How to login and then download a file from aspx web pages with R library(RCurl) curl = getCurlHandle() curlSetOpt(cookiejar = 'cookies.txt', followlocation = TRUE, autoreferer = TRUE, curl = curl) html <- getURL('http://www.aceanalyser.com/Login.aspx', curl = curl) viewstate <- as.character(sub('.*id="__VIEWSTATE" value="([0-9a-zA-Z+/=]*).*', '\\1', html)) viewstategenerator <- as.character(sub('.*id="__VIEWSTATEGENERATOR" value="([0-9a-zA-Z+/=]*).*', '\\1', html))

R: fetching pdf documents from Companies House API

旧时模样 提交于 2019-12-05 02:51:14
I'm trying to fetch documents from the API using R. Appreciate the clarification of the process in this post . I've been following the above steps with partial success, but still fail the last step to get access to documents' content: Find the document filing you're interested in (e.g. make a filing history request1 for the company). Parse the response for the link to the document in the field "links" : { "document_metadata" : "link URI fragment here" }. No problem: library(httr) library(jsonlite) library(openssl) ### retrieving filing history #### company_num = 'FC013908' key = 'my_key' fh

R + httr and EC2 api authentication issues

半腔热情 提交于 2019-12-05 01:40:45
问题 I would like to use the R package httr to access the EC2 services via their API. But I am a little bit unsure how to get started as it does not fall into the usual authentication format of "Oauth2.0" in which you have the usual: key, secret, token and signature system. I think EC2 uses the "signature version 2" method, but I am unclear as to how that works. Looking at the documentation that EC2 provides with regard to making query requests at http://docs.amazonwebservices.com/AWSEC2/latest