我正在尝试使用R脚本运行google app脚本。 Google应用程序脚本允许使用doPost(e)命令执行脚本。我已经写了我谷歌应用程序脚本,并完成了作为Web应用程序的部署。我已经收到执行URL(以我为例,假设我已经收到“ https://script.google.com/macros/s/xyz/exec”作为执行URL)。
我正在使用“ httr”包来发布和执行上述URL。我的R代码是:-
// hope this would be usefull
// i used these codes for auto completing the texts in textarea.
// other methods change all matching items before the selected text
// but this affects only the text where caret on.
// at first, i divided textarea.value into 3 pieces. these are ;
// p1; until the 'searched' item, p2 after 'searched' item
// and pa = new item that will replaced with 'searched' item
// then, i combined them together again.
var tea = document.getElementById(targetTextArea);
caretPosition = tea.selectionStart - ara.length; //ara=searched item
p1 = tea.value.substring(0,caretPosition);
console.log('p1 text : ' + p1);
p2 = tea.value.substring(caretPosition+ara.length,tea.value.length);
console.log('p2 text : ' + p2);
pa = yeni; //new item
console.log('pa text : ' + pa);
tea.value = p1 + pa + p2;
tea.selectionStart = caretPosition + yeni.length;
tea.selectionEnd = caretPosition + yeni.length;
tea.focus();
我收到此错误:-
library(httr)
x <- 'https://script.google.com/macros/s/xyz/exec'
POST(x,body= NULL,verbose())
我从以下错误中得到了答案:-
-> POST /macros/s/xyz/exec HTTP/1.1
-> Host: script.google.com
-> User-Agent: libcurl/7.59.0 r-curl/3.2 httr/1.3.1
-> Accept-Encoding: gzip, deflate
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Length: 0
->
<- HTTP/1.1 401 Unauthorized
<- Cache-Control: no-cache, no-store, max-age=0, must-revalidate
<- Pragma: no-cache
<- Expires: Mon, 01 Jan 1990 00:00:00 GMT
<- Date: Fri, 16 Nov 2018 08:19:15 GMT
<- Content-Type: text/html; charset=utf-8
<- Content-Encoding: gzip
<- x-chromium-appcache-fallback-override: disallow-fallback
<- X-Content-Type-Options: nosniff
<- X-XSS-Protection: 1; mode=block
<- Server: GSE
<- Alt-Svc: quic=":443"; ma=2592000; v="44,43,39,35"
<- Transfer-Encoding: chunked
但是我的R服务器已经使用httr-oauth连接到varion google服务。
任何机构都有更好的解决方案,或者可以找到代码中的错误,在此先感谢您。