Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中使用httr包将映像发布到slack_R_Slack_Httr - Fatal编程技术网

在R中使用httr包将映像发布到slack

在R中使用httr包将映像发布到slack,r,slack,httr,R,Slack,Httr,Slack提供了一种通过api上传文件的方法。文档可在此处找到: 本页给出了如何发布文件的示例: curl -F file=@dramacat.gif -F "initial_comment=Shakes the cat" -F channels=C024BE91L,D032AC32T -H "Authorization: Bearer xoxa-xxxxxxxxx-xxxx" https://slack.com/api/files.upload 我试图翻译如何使用R中的httr包执行这一行

Slack提供了一种通过api上传文件的方法。文档可在此处找到:

本页给出了如何发布文件的示例:

curl -F file=@dramacat.gif -F "initial_comment=Shakes the cat" -F channels=C024BE91L,D032AC32T -H "Authorization: Bearer xoxa-xxxxxxxxx-xxxx" https://slack.com/api/files.upload
我试图翻译如何使用R中的httr包执行这一行代码,其中一个文件位于我的R工作目录中。我无法翻译命令的不同部分。这是我到目前为止所拥有的

api_token='******'
f_path='c:/mark/consulting/dreamcloud' #this is also my working directory
f_name='alert_picture.png'

res<-httr::POST(url='https://slack.com/api/files.upload', httr::add_headers(`Content-Type` = "multipart/form-data"), 
      body = list(token=api_token, channels='CCJL7TMC7', title='test', file = httr::upload_file(f_path), filename=f_name))
我试图找到更好的例子来使用,但到目前为止没有运气。任何建议都将不胜感激

,创建GGPlot的图像并将其上载到Slack:

  res <- POST(url="https://slack.com/api/files.upload",
              add_headers(`Content-Type`="multipart/form-data"),
              body=list(file=upload_file(ftmp),
                        token=api_token, channels=modchan))

你真是个天才!最初它不起作用,因为'modchan'参数实际上是一个将频道名称转换为频道ID的函数。不确定为什么它不起作用,但当我用实际的频道ID替换它时,它发布了图像。你是救命恩人!很高兴我能帮忙!
  res <- POST(url="https://slack.com/api/files.upload",
              add_headers(`Content-Type`="multipart/form-data"),
              body=list(file=upload_file(ftmp),
                        token=api_token, channels=modchan))