Exemple #1
0
func sendTweet(c context.Context, title string, path string, tags []string) error {
	spreadsheetsID := "1Vk83CXQacadLSBgguE9UJ1_l5_qX072cmy4ieiwh7HU"
	sheetID := "1373105893"
	sheet, err := gapps.GetSpreadsheet(c, spreadsheetsID, sheetID)
	if err != nil {
		return err
	}
	log.Infof(c, title)
	consumerKey := sheet.Table.Rows[1].C[0].V
	consumerSecret := sheet.Table.Rows[1].C[1].V
	accessToken := sheet.Table.Rows[1].C[2].V
	accessTokenSecret := sheet.Table.Rows[1].C[3].V

	tagString := ""
	for _, tag := range tags {
		if strings.HasPrefix(tag, "@") {
			tagString += " " + tag
		} else {
			tagString += " #" + tag
		}
	}

	anaconda.SetConsumerKey(consumerKey)
	anaconda.SetConsumerSecret(consumerSecret)
	api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
	api.HttpClient.Transport = &urlfetch.Transport{Context: c}
	_, err = api.PostTweet(title+" "+path+tagString, nil)
	if err != nil {
		log.Infof(c, err.Error())
	}

	return nil
}
Exemple #2
0
func sendTweet(c context.Context, spreadsheetsID string, sheetID string, title string, path string, tags []string) error {
	sheet, error := gapps.GetSpreadsheet(c, spreadsheetsID, sheetID)
	if error != nil {
		return error
	}
	log.Infof(c, title)
	consumerKey := sheet.Table.Rows[1].C[0].V
	consumerSecret := sheet.Table.Rows[1].C[1].V
	accessToken := sheet.Table.Rows[1].C[2].V
	accessTokenSecret := sheet.Table.Rows[1].C[3].V

	tagString := ""
	for _, tag := range tags {
		tagString += " #" + tag
	}

	anaconda.SetConsumerKey(consumerKey)
	anaconda.SetConsumerSecret(consumerSecret)
	api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
	api.HttpClient.Transport = &urlfetch.Transport{Context: c}
	_, error = api.PostTweet(title+" "+path+tagString, nil)
	if error != nil {
		log.Infof(c, error.Error())
	}
	return nil
}