I’ve the below Google Apps script:
function doGet(request) {
var events = CalendarApp.getEvents(
new Date(Number(request.parameters.start) * 1000),
new Date(Number(request.parameters.end) * 1000));
var result = {
available: events.length == 0
};
return ContentService.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
Once I open the following url at browsr:
https://script.google.com/macros/s/AKfycbwNGgAO-p4TrbKLdGj_blwm5nI9nD5i_0EtlnS42-PuVsrxrM3Ovvwfdw/exec?end=1325439000&start=1325437200
I get correct responce:
{"available":true}
I’m trying to do the call through Go lang as:
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
)
func main() {
site := "https://script.google.com/macros/s/AKfycbwNGgAO-p4TrbKLdGj_blwm5nI9nD5i_0EtlnS42-PuVsrxrM3Ovvwfdw/exec"
base, err := url.Parse(site)
if err != nil {
return
}
// Path params
// base.Path += "this will get automatically encoded"
// Query params
params := url.Values{}
params.Add("start", "1325437200")
params.Add("end", "1325439000")
base.RawQuery = params.Encode()
fmt.Printf("Encoded URL is %q\n", base.String())
// make a sample HTTP GET request
res, err := http.Get(base.String())
// check for response error
if err != nil {
log.Fatal(err)
}
// read all response body
data, _ := ioutil.ReadAll(res.Body)
// close response body
res.Body.Close()
// print `data` as a string
fmt.Printf("%s\n", data)
}
But I’m not getting the same output, and getting very long text looks to be like extraction of Google login screen with multiple languages (regardless what the output is, it is not the expected one), I expect the output to be same what I got at the browser, i.e.
{"available":true}