从 R 发送 cURL 命令

Send cURL command from R

mailerLite 是一个管理联系人和发送电子邮件的 SaaS。我正在尝试使用他们的 API 向我的帐户添加内容。

他们的 API 是建立在 HTTP 之上的 RESTful。根据他们的文档 here,我可以看到我是如何对列表进行分段的。有一个 PHP 和 cURL 示例:

curl -v https://api.mailerlite.com/api/v2/segments
-H "X-MailerLite-ApiKey: my-api-key"

这在我的 Mac 上的终端提示符下成功运行。 现在我想从 R.

做同样的事情

我试过这个:

apiKey <- "my-api-key"
result <- GET("https://api.mailerlite.com/api/v2/segments", add_headers(Authorization = paste("X-MailerLite-ApiKey", apiKey)))
result
# Status 401: Unauthorized

此外,我对 R 包之间的差异感到困惑:RCurl、httr、curl 和 crul。

也许试试

GET("https://api.mailerlite.com/api/v2/segments", add_headers(`X-MailerLite-ApiKey` = apiKey))