2013-02-27 45 views
1

我正在嘗試使用PATCH更新Google網上論壇,但無法使其工作。我不確定它是否是一個語法問題,或者它不能通過Javascript完成。我可以使用OAUTH成功執行「獲取」操作,但不能使用PATCH。嘗試通過Javascript更新Google網上論壇與PATCH

  1. 我應該使用OAuth或承載在setRequestHeader「授權」(似乎都爲GET做工精細,並在「補丁」以同樣的方式失敗。
  2. 的get工作正常。上的錯誤PATCH是{「error」:{「errors」:[{「domain」:「global」,「reason」:「invalid」,「message」:「Permission denied:Can not hide from Groups directory。」}],「code 「:400, 「消息」: 「權限被拒絕:無法從組隱藏目錄」}}

    <!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> 
    

回答

0

嘿,我得到了同樣的問題,我通過創建一個新的Groups對象[Java]並設置了我想更新的特定屬性來修復它

相關問題