2014-03-26 84 views
0

當我獲取我的谷歌應用程序腳本時,出現以下錯誤。如何關注Google Apps Script中的HTTPResponse?

ERROR: The script completed but did not return anything. 

因爲我將張貼到我的應用程序(後完成時會被重定向到我的應用程序),我應該被自動重定向回我的應用程序?

function doGet(e){ 
    var options = { 
    "method" : 'POST', 
    "payload" : "user_id="+e.parameter.user_id+"&gmail="+getEmail() 
    }; 
    var url = 'http://somedomain.com/users/give_gmail_permission/'; 
    var response = UrlFetchApp.fetch(url, options); 
    return response; 
} 

我在做什麼錯?如何關注Google Apps Script中的HTTPResponse?

回答

1

更改的行:

return response 

return HtmlService.createHtmlOutput("<b>"+response.getResponseCode()+"</b><br>"+response.getContentText()). 
    setSandboxMode(HtmlService.SandboxMode.NATIVE); 

修改後的腳本:

function doGet(e){ 
    var options = { 
    "method" : 'POST', 
    "payload" : "user_id="+e.parameter.user_id+"&gmail="+getEmail() 
    }; 
    var url = 'http://somedomain.com/users/give_gmail_permission/'; 
    var response = UrlFetchApp.fetch(url, options); 
    Logger.log("response code: "+response.getResponseCode()); 
    Logger.log("response: "+response.getContentText()); 
    return HtmlService.createHtmlOutput("<b>"+response.getResponseCode()+"</b><br>"+response.getContentText()). 
    setSandboxMode(HtmlService.SandboxMode.NATIVE); 
} 
相關問題