无法使用 R 连接到 todoist REST API

Cannot connect to todoist REST API with R

可以说,我不太擅长与 API 的 "From scratch" 一起工作。我这里的问题可能更多是因为我对 RESTful API 的无知,而不是具体的 Todoist API,但我正在与 Todoist 斗争,因为他们所有的文档都是围绕 python 而且我不确定为什么我的微弱尝试失败了。一旦我得到 connected/authenticated 我想我会没事的。

Todoist documentation

我使用 httr::GET() 尝试了几种配置。我会很感激在我开始时在这里推动一下。

我尝试过的事情,其中​​ key 是我的 api 令牌:

library(httr)
r<-GET("https://beta.todoist.com/API/v8/", add_headers(hdr))

对于 hdr,我使用了很多东西:

我也在 url

的末尾尝试了 projects

UPDATE 这些现在在 R 包中实现 rtodoist


我想除了 url 之外,您几乎已经拥有它了? (或者从那时起它可能发生了变化)和 header。以下对我有用,将 my_todoist_token 替换为 API 找到的令牌 here.

library(jsonlite)
library(httr)
projects_api_url <- "https://api.todoist.com/rest/v1/projects"

# to get the project as a data frame
header <- add_headers(Authorization = paste("Bearer ", my_todoist_token))
project_df <- GET(url = projects_api_url, header) %>%
  content("text", encoding = "UTF-8") %>%
  fromJSON(flatten = TRUE)

# to create a new project
# unfortunately no way to change the dot color associated with project
header2 <- add_headers(
  Authorization  = paste("Bearer ", my_todoist_token),
  `Content-Type` = "application/json",
  `X-Request-Id` = uuid::UUIDgenerate())

POST(url = projects_api_url, header2,
     body = list(name = "Your New Project Name"
                 # parent = parentID
                 ),
     encode = "json")

# get a project given project id
GET(url = paste0(projects_api_url, "/", project_df$id[10]),
    header) %>%
  content("text", encoding = "UTF-8") %>%
  fromJSON(flatten = TRUE)

# update a project 
POST(url = paste0(projects_api_url, "/", project_df$id[10]),
    header2, body = list(name = "IBS-AR Biometric 2019"), encode = "json")