I am attempting to access the inoreader API in R
using the httr
package. So far I am failing because of my limited understanding of how an API request work. I was wondering if anyone could help me to get started, by creating a function to retrieve the OAuth 2.0 bearer token.
This is where I got so far:
library(httr); library(jsonlite)
token <- function(client_id_f, redirect_uri_f) {
POST("/oauth2/token HTTP/1.1",
config=add_headers(
`Host`="www.inoreader.com",
`Content-length`="217",
`Content-type`="application/x-www-form-urlencoded",
`User-agent`="your-user-agent"
),
body = list(client_id=client_id_f,
redirect_uri=redirect_uri_f,
scope='read',
state='guydqwgusadhdashijdsahj')
)-> res
stop_for_status(res)
content(res)
}
And unsurprisingly the response is URL rejected: Malformed input to a URL function
. Any help would be appreciated.
I just found an answer I thought it would be worth sharing.
#libraries
library(httr2); library(tidyverse)
#set up client
inoreader_client <- function() {oauth_client(
id = your_id,
token_url = "https://www.inoreader.com/oauth2/token",
secret=obfuscated(your_token),
name = your_name)}
# get stream
stream <- request('https://www.inoreader.com/reader/api/0/stream/contents/user%2F')` %>%
req_oauth_auth_code(
client = inoreader_client(),
scope="read",
auth_url = "https://www.inoreader.com/oauth2/authorize",
redirect_uri = 'http://localhost:1410/') %>%
req_url_query(n=999) %>%
req_perform() %>%
resp_body_json(simplifyVector = TRUE)