1 function onOpen() { 2 var ss = SpreadsheetApp.getActiveSpreadsheet(); 3 var menuEntries = [ {name: "Import Goals", functionName: "importGoals"} ]; 4 ss.addMenu("43things", menuEntries); 5 } 6 7 function importGoals() { 8 name = Browser.inputBox("43things Username"); 9 goalsResponse = UrlFetchApp.fetch("http://www.43things.com/service/get_person?api_key=1234&id=" + name); 10 goalsXmlDocument = Xml.parse(goalsResponse.getContentText()); 11 root = goalsXmlDocument.getElement(); 12 open_goals = root.getElement("open_goals"); 13 goals = open_goals.getElements(); 14 var data = []; 15 uberschrift = ["Goal","Title","Entry"]; 16 data.push(uberschrift); 17 for(var i=0; i < goals.length; i++) { 18 var values = []; 19 values.push(goals[i].getElement("name").getText()); 20 values.push(""); 21 values.push(""); 22 data.push(values); 23 goalId = goals[i].getAttribute("goal_id").getValue(); 24 25 entriesResponse = UrlFetchApp.fetch("http://www.43things.com/service/get_persons_progress_on_goal?api_key=1234&id="+ name +"&goal_id=" + goalId) 26 entriesXmlDocument = Xml.parse(entriesResponse.getContentText()); 27 entriesRoot = entriesXmlDocument.getElement(); 28 entries = entriesRoot.getElements("entry"); 29 for(var j=0; j < entries.length; j++) { 30 values = []; 31 values.push(""); 32 values.push(entries[j].getElement("title").getText()); 33 values.push(entries[j].getElement("unformatted_content").getText()); 34 data.push(values); 35 } 36 37 sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; 38 destinationRange = sheet.getRange(1, 1, data.length, 3); 39 destinationRange.setValues(data); 40 } 41 42 } ?