使用RCurl对Twilio API进行未经授权的错误

时间:2015-03-23 08:42:35

标签: r twilio rcurl

我正在尝试使用httpPOST(R中的RCurl Package)消息来使用Twilio API发送短信。获取未经授权的错误。

httpPOST(url ="https://{sid}:{auth_token}@api.twilio.com/2010-04-01/Accounts/{sid}/Messages",Body = "HI",From = "+15042520074", To = "+658XXX")

我不想在R中为Twilio使用devtools :: RTwilio包装。

你能告诉我为什么会收到这个错误吗?

1 个答案:

答案 0 :(得分:0)

Twilio福音传教士在这里。

您似乎并没有将您的请求声明为Basic Authentication.不这样做会给您Unauthorized Error

尝试将您的请求更改为:

 options(RCurlOptions = list(
 cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"),
 httpauth=AUTH_BASIC
)
)

the_url <- paste("https://api.twilio.com/2010-04-01/Accounts/",{sid},"/Messages.XML",sep="")
postForm(the_url,
         .opts = list(
           userpwd = paste({sid},":",{auth_token},sep=""),
           useragent = "RCurl",
           verbose = TRUE
         ),
         .params = c(From = "+15042520074", 
                     To = "+658XXX", 
                     Body = "Hi" 
         )
)

有关this website的更多信息。