I could use some help with creating a script when a Google Form is submitted.
Once the form submitted, the script automatically prints a Google Spreadsheet to a Google Cloud-based printer without bringing up the print dialog window.
I've read through Google Cloud Print Info
The idea behind the script is simple:
- User fills out form
- Form is then submitted
- Script updates cells with information user put in
- Script then prints to google cloud printer
- Shipping label is ready
The below script will print a ticket but how do i add the printer capabilities to the POST request?
The code I have so far:
function onsubmit(e) {
var pid = "123456789"; //place printer id here
var sheetid = "123456789"; //place sheet id here
var ss = SpreadsheetApp.getActiveSpreadsheet();
var info = ss.getSheetByName('Form responses 1');
var lastRow = info.getLastRow();
var sheet = SpreadsheetApp.setActiveSheet(ss.getSheetByName('TICKET'))
authorize();
var url = "https://www.google.com/cloudprint/submit?printerid="+pid+"&contentType=google.spreadsheet&content="+sheetid+"&title=PrintingTicket";
var options = {
method: "post",
oAuthServiceName : "print",
oAuthUseToken : "always"
};
info.hideSheet();
var response = UrlFetchApp.fetch(url, options);
return Utilities.jsonParse(response.getContentText());
}
function authorize() {
var oauthConfig = UrlFetchApp.addOAuthService("print");
var scope = "https://www.googleapis.com/auth/cloudprint";
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
}
User credentials required
Error... (use muteHttpExceptions option to examine full response). (line 20, file "Code") Any help would be much appreciated
– BBV May 13 '14 at 06:55