示例#1
0
文件: main.go 项目: amrhassan/rsc
func main() {
	flag.Usage = usage
	flag.Parse()
	if flag.NArg() != 1 {
		usage()
	}

	log.SetFlags(0)

	tr, err := oauthprompt.GoogleToken(".token-spreadsheets.google.com", apiClientID, apiClientSecret, apiScope)
	if err != nil {
		log.Fatal(err)
	}
	client = tr.Client()

	r, err := client.Get(feed + url.QueryEscape(flag.Arg(0)))
	if err != nil {
		log.Fatal(err)
	}
	if r.StatusCode != http.StatusOK {
		log.Fatalf("reading spreadsheet list: %v", r.Status)
	}
	data, err := ioutil.ReadAll(r.Body)

	var list DocList
	if err := xml.Unmarshal(data, &list); err != nil {
		log.Fatalf("parsing spreadsheet list: %v", err)
	}

	if !strings.HasPrefix(list.ID, "spreadsheet:") {
		dumpxml(bytes.NewBuffer(data))
		log.Fatalf("did not find spreadsheet - id is %s", list.ID)
	}
	r.Body.Close()

	url := download + list.ID[len("spreadsheet:"):]
	r, err = client.Get(url)
	if err != nil {
		log.Fatalf("download: %v", err)
	}
	if r.StatusCode != http.StatusOK {
		log.Fatalf("download: %v", r.Status)
	}
	defer r.Body.Close()
	data, err = ioutil.ReadAll(r.Body)
	if err != nil {
		log.Fatalf("download: %v", err)
	}
	if len(data) > 0 && data[len(data)-1] != '\n' {
		data = append(data, '\n')
	}

	os.Stdout.Write(data)
}
示例#2
0
文件: issue.go 项目: amrhassan/rsc
func login() error {
	if false {
		data, err := ioutil.ReadFile("../../authblob")
		if err != nil {
			return err
		}
		if err := json.Unmarshal(data, &auth); err != nil {
			return err
		}
	}

	auth.APIClientID = "993255737644.apps.googleusercontent.com"
	auth.APIClientSecret = "kjB02zudLVECBmJdKVMaZluI"

	tr, err := oauthprompt.GoogleToken(".token-code.google.com", auth.APIClientID, auth.APIClientSecret, "https://code.google.com/feeds/issues")
	if err != nil {
		return err
	}
	client = tr.Client()
	return nil
}