在 R 中设置 inoreader API

问题描述 投票:0回答:1

我正在尝试使用

R
包访问
httr
中的 inoreader API。到目前为止,由于我对 API 请求如何工作的理解有限,我失败了。我想知道是否有人可以帮助我开始,通过创建一个函数来检索 OAuth 2.0 不记名令牌

这就是我到目前为止所得到的:

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)
    }

毫不奇怪,反应是

URL rejected: Malformed input to a URL function
。任何帮助将不胜感激。

r post httr
1个回答
0
投票

我刚刚找到了一个我认为值得分享的答案。

#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) 
© www.soinside.com 2019 - 2024. All rights reserved.