1

我正在尝试使用 PATCH 更新 Google 组,但无法使其正常工作。我不确定这是语法问题还是无法通过 Javascript 完成。我可以使用 OAUTH 成功执行“获取”操作,但不能使用 PATCH。

  1. 我应该在 setRequestHeader “Authorization”中使用 OAuth 还是 Bearer(两者似乎都适用于 GET 并且在“PATCH”期间以相同的方式失败。
  2. get 工作正常。PATCH 上的错误是 { "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "Permission denied: Cannot hide from Groups directory." } ], "code": 400, "message": "Permission denied: 无法从 Groups 目录中隐藏。" } }

    <!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!\n\nThe response representation was:\n\n" + xmlhttppatcher.responseText);
    else
    alert("The request did not succeed!\n\nThe 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!\n\nThe response representation was:\n\n" + xmlhttp.responseText);
    else
    alert("The request did not succeed!\n\nThe 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>
    

4

1 回答 1

0

嘿,我遇到了同样的问题,我通过创建一个新的 Groups 对象 [Java] 并设置了我想要更新的特定属性来修复它

于 2013-03-04T17:06:35.493 回答