我正在尝试使用PATCH更新谷歌组,无法让它工作。我不确定这是否是一个语法问题,或者它不能通过Javascript完成。我可以使用OAUTH成功执行"get"操作,但不能使用PATCH。
- 我应该在setRequestHeader"授权"中使用OAuth或Bearer(两者似乎都适用于GET,并在"PATCH"期间以相同的方式失败。
-
get工作正常。PATCH上的错误为{"error": {"errors": [{"domain": "global", "reason": "invalid", "message": "Permission denied: Cannot hide from Groups directory "。}], "code": 400, "message": "Permission denied: Cannot hide from Groups directory."}}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function loadXMLDoc() { var xmlhttppatcher; var xmlhttp; var data; if (window.XMLHttpRequest) { xmlhttppatcher = new XMLHttpRequest(); xmlhttppatcher.open("PATCH","https://www.googleapis.com/groups/v1/groups/nogads2%40mydomain.org", false); xmlhttppatcher.setRequestHeader("Content-Type", "application/json"); xmlhttppatcher.setRequestHeader("Authorization", "OAuth " + "ya29.AHES6ZR_yljyMvWCv0gWbwIASYYp29S8rFUA-dd-YkyyjTHz"); //xmlhttppatcher.setRequestHeader("Authorization", "Bearer " + "ya29.AHES6ZR_yljyMvWCv0gWbwIASYYp29S8rFUA-dd-YkyyjTHz"); data = '{"replyTo": "REPLY_TO_MANAGERS"}'; alert(data); xmlhttppatcher.send(data); alert('Your data was sent'); document.getElementById("myDiv1").innerHTML = xmlhttppatcher.responseText; alert('readystate: ' + xmlhttppatcher.readyState + ' status: ' + xmlhttppatcher.status); //this should return 4 & 200 if (xmlhttppatcher.status == 200) alert("The request succeeded!nnThe response representation was:nn" + xmlhttppatcher.responseText); else alert("The request did not succeed!nnThe response status was: " + xmlhttppatcher.status + " " + xmlhttppatcher.statusText + "."); } if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "https://www.googleapis.com/groups/v1/groups/nogads2%40mydomain.org?alt=json", false); xmlhttp.setRequestHeader("Authorization", "OAuth " + "ya29.AHES6ZR_yljyMvWCv0gWbwIASYYp29S8rFUA-dd-YkyyjTHz"); xmlhttp.send(); alert('readystate: ' + xmlhttp.readyState + ' status: ' + xmlhttp.status); //this should return 4 & 200 document.getElementById("myDiv2").innerHTML = xmlhttp.responseText; if (xmlhttp.status == 200) alert("The request succeeded!nnThe response representation was:nn" + xmlhttp.responseText); else alert("The request did not succeed!nnThe response status was: " + xmlhttp.status + " " + xmlhttp.statusText + "."); } } </script> </head> <body> <div id="myDiv1"><h2>Let AJAX change this text (DIV1)</h2></div><br /> <div id="myDiv2"><h2>Let AJAX change this text (DIV2)</h2></div> <button type="button" onclick="loadXMLDoc()">Change Content</button> </body>
嘿,我遇到了同样的问题,我通过创建一个新的Groups对象[Java]并设置我想要更新的特定属性来修复它