无法使用 httr 包连接到 Qualtrics API
我正在尝试使用 Rstudio Cloud“httr”包连接到 Qualtrics API 以下载邮件列表。查看 API 文档后,我无法下载数据,运行代码后出现以下错误:
"{"meta":{"httpStatus":"400 - Bad Request","error":{ “errorMessage”:“标头中预期有授权,但没有提供。","errorCode":"ATP_2"},"requestId":"8fz33cca-f9ii-4bca-9288-5tc69acaea13"}}"
这对我来说没有任何意义,因为我使用的是继承身份验证父令牌。这是代码:
install.packages("httr")
library(httr)
directoryId<-"POOL_XXXXX"
mailingListId <- "CG_XXXXXX"
apiToken<-"XXXX"
url<- paste("https://iad1.qualtrics.com/API/v3/directories/",directoryId,
"/mailinglists/",mailingListId,"/optedOutContacts", sep = "")
response <- VERB("GET",url, add_headers('X_API-TOKEN' = apiToken),
content_type("application/octet-stream"))
content(response, "text")
任何帮助将不胜感激。
提前致谢。
I am trying to connect to Qualtrics API using Rstudio Cloud "httr" package to download mailing lists. After a review of the API documentation I was unable to download the data, getting the following error after running the code:
"{"meta":{"httpStatus":"400 - Bad Request","error":{"errorMessage":"Expected authorization in headers, but none provided.","errorCode":"ATP_2"},"requestId":"8fz33cca-f9ii-4bca-9288-5tc69acaea13"}}"
This does not makes me any sense since I am using a inherit auth from parent token. Here is the code:
install.packages("httr")
library(httr)
directoryId<-"POOL_XXXXX"
mailingListId <- "CG_XXXXXX"
apiToken<-"XXXX"
url<- paste("https://iad1.qualtrics.com/API/v3/directories/",directoryId,
"/mailinglists/",mailingListId,"/optedOutContacts", sep = "")
response <- VERB("GET",url, add_headers('X_API-TOKEN' = apiToken),
content_type("application/octet-stream"))
content(response, "text")
Any help will be appreciated.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对 httr::VERB 的调用将 API 令牌和内容类型分解为函数的两个参数,但它们应该在向量中一起传递给单个“config”参数。此外,content_type 不是一个函数,它只是该标头向量中元素的名称。这应该有效:
请注意,Qualtrics 将返回邮件列表作为列表,其中将包含“meta”元素和“result”元素,这两个元素本身都是列表。如果列表很长,则仅返回列表中的前100个联系人;将有一个元素response$result$nextpage,它将提供访问接下来的100个结果所需的URL。 qualtRics::fetch_mailinglist() 函数 不适用于XM Directory 联系人列表(这可能就是您在使用它时收到 500 错误的原因),但是用于解压列表并循环每个“nextpage”元素的代码可能会有所帮助。
Your call to httr::VERB breaks the API token and the content type into two arguments to the function, but they should be passed together in a vector to a single "config" argument. Also, content_type isn't a function, it's just the name of an element in that header vector. This should work:
Note that mailing lists will be returned by Qualtrics as lists that will include both a "meta" element and a "result" element, both of which will themselves be lists. If the list is long, the only the first 100 contacts on the list will be returned; there will be an element response$result$nextpage that will provide the URL required to access the next 100 results. The qualtRics::fetch_mailinglist() function does not work with XM Directory contact lists (which is probably why you got a 500 error when using it), but the code for unpacking the list and looping over each "nextpage" element might be helpful.