Ejemplo n.º 1
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	aga := gads.NewAdGroupAdService(&config.Auth)

	ads, err := aga.Mutate(
		gads.AdGroupAdOperations{
			"ADD": {
				gads.ExpandedTextAd{
					AdGroupId:     1234567890,
					FinalUrls:     []string{"https://classdo.com/en"},
					Path1:         "path1",
					Path2:         "path2",
					HeadlinePart1: "test headline",
					HeadlinePart2: "test headline2",
					Description:   "test line one",
				},
			},
		},
	)

	fmt.Println(ads)
	adsJSON, err := json.MarshalIndent(ads, "", "  ")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", adsJSON)

}
Ejemplo n.º 2
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	// User List Service
	auls := gads.NewAdwordsUserListService(&config.Auth)

	crmList := gads.NewCrmBasedUserList("Test List", "Just a list to test with", 0, "http://mytest.com/optout")

	ops := gads.UserListOperations{
		Operations: []gads.Operation{
			gads.Operation{
				Operator: "ADD",
				Operand:  crmList,
			},
		},
	}

	resp, err := auls.Mutate(ops)

	if err != nil {
		panic(err)
	}

	fmt.Println(resp[0].Id)

	mmo := gads.NewMutateMembersOperand()
	mmo.UserListId = resp[0].Id

	var members []string
	members = append(members, "*****@*****.**")
	members = append(members, "*****@*****.**")

	mmo.Members = members

	mutateMembersOperations := gads.MutateMembersOperations{
		Operations: []gads.Operation{
			gads.Operation{
				Operator: "ADD",
				Operand:  mmo,
			},
		},
	}

	lists, err := auls.MutateMembers(mutateMembersOperations)

	if err != nil {
		panic(err)
	}

	fmt.Println(lists)
}
Ejemplo n.º 3
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	cs := gads.NewCampaignCriterionService(&config.Auth)

	//bidmodifier := float64(2)
	//var bidmodifier float64
	//bidmodifier = 1.04

	campaignCriterions := gads.CampaignCriterions{
		gads.NegativeCampaignCriterion{
			CampaignId: 123456789,
			Criterion: gads.Location{
				Id: 21168,
			},
		},
		gads.CampaignCriterion{
			CampaignId: 123456789,
			Criterion: gads.Location{
				Id: 21167,
			},
		},
	}

	criterions, err := cs.Mutate(
		gads.CampaignCriterionOperations{
			"ADD": campaignCriterions,
		},
	)

	fmt.Println(criterions)
	criterionJSON, _ := json.MarshalIndent(criterions, "", "  ")
	fmt.Printf("%s\n", criterionJSON)

	// show all Location Criterion
	fmt.Printf("Campaign Criterion\n")
	foundCriterions, totalCount, err := cs.Query("SELECT CampaignId,IsNegative,BidModifier,CriteriaType,Id,LocationName,DisplayType,ParentLocations WHERE CampaignId = '211793582' AND CriteriaType IN ['LOCATION']")
	fmt.Println(totalCount)
	if err != nil {
		log.Fatal(err)
	}
	for _, criterion := range foundCriterions {
		criterionJSON, _ := json.MarshalIndent(criterion, "", "  ")
		fmt.Printf("%s\n", criterionJSON)
	}

}
Ejemplo n.º 4
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	// Report Service
	rs := gads.NewReportDownloadService(&config.Auth)

	res, err := rs.AWQL(awql, "CSV")

	if err != nil {
		log.Panicln(err)
	}

	log.Println(res)
}
Ejemplo n.º 5
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	cs := gads.NewCustomerService(&config.Auth)

	customers, err := cs.GetCustomers()

	fmt.Println(customers)
	customersJSON, err := json.MarshalIndent(customers, "", "  ")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", customersJSON)

}
Ejemplo n.º 6
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	// show all Keywords
	cs := gads.NewAdGroupCriterionService(&config.Auth)
	fmt.Printf("Keywords\n")
	foundKeywords, totalCount, err := cs.Query("SELECT Id, KeywordText, KeywordMatchType WHERE AdGroupId = '123'")
	fmt.Println(totalCount)
	if err != nil {
		log.Fatal(err)
	}
	for _, keyword := range foundKeywords {
		keywordJSON, _ := json.MarshalIndent(keyword, "", "  ")
		fmt.Printf("%s\n", keywordJSON)
	}

}
Ejemplo n.º 7
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}
	// show all Campaigns
	cs := gads.NewAdGroupService(&config.Auth)
	fmt.Printf("AdGroups\n")

	foundAdGroups, totalCount, err := cs.Query("SELECT AdGroupId, Name, Status WHERE CampaignId = '123'")
	fmt.Println(totalCount)
	if err != nil {
		log.Fatal(err)
	}
	for _, adGroup := range foundAdGroups {
		adGroupJSON, _ := json.MarshalIndent(adGroup, "", "  ")
		fmt.Printf("%s\n", adGroupJSON)
	}

}
Ejemplo n.º 8
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	config.Auth.PartialFailure = true

	service := gads.NewAdGroupService(&config.Auth)

	adGroupList := []gads.AdGroupLabel{
		gads.AdGroupLabel{
			AdGroupId: 1234567890,
			LabelId:   1234567,
		},
		gads.AdGroupLabel{
			AdGroupId: 1234567891,
			LabelId:   1234567,
		},
		gads.AdGroupLabel{
			AdGroupId: 1234567892,
			LabelId:   1234567,
		},
	}

	adGroupLabels, err := service.MutateLabel(
		gads.AdGroupLabelOperations{
			"ADD": adGroupList,
		},
	)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(adGroupLabels)

}
Ejemplo n.º 9
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	service := gads.NewDataService(&config.Auth)

	// Test GetAdGroupBidLandscape

	adGroupBidLandscape, _, err := service.GetAdGroupBidLandscape(
		gads.Selector{
			Fields: []string{
				"AdGroupId",
				"Bid",
				"CampaignId",
				"LocalClicks",
				"LocalCost",
				"LocalImpressions",
				"PromotedImpressions",
				"StartDate",
				"EndDate",
			},
			Predicates: []gads.Predicate{
				{"AdGroupId", "EQUALS", []string{adGroupId}},
			},
		},
	)

	if err != nil {
		log.Fatal(err)
	}

	for _, bidLandscape := range adGroupBidLandscape {
		landscapeJSON, _ := json.MarshalIndent(bidLandscape, "", "  ")
		fmt.Printf("%s\n", landscapeJSON)
	}

	// END Test GetAdGroupBidLandscape

	// Test QueryAdGroupBidLandscape

	foundBidLandscape, _, err := service.QueryAdGroupBidLandscape(fmt.Sprintf("SELECT AdGroupId, Bid, CampaignId, LocalClicks, LocalCost, LocalImpressions WHERE AdGroupId = '%v'", adGroupId))

	if err != nil {
		log.Fatal(err)
	}

	for _, bidLandscape := range foundBidLandscape {
		landscapeJSON, _ := json.MarshalIndent(bidLandscape, "", "  ")
		fmt.Printf("%s\n", landscapeJSON)
	}

	// END Test QueryAdGroupBidLandscape

	// Test GetCriterionBidLandscape

	criterionBidLandscape, _, err := service.GetCriterionBidLandscape(
		gads.Selector{
			Fields: []string{
				"AdGroupId",
				"Bid",
				"CampaignId",
				"CriterionId",
				"LocalClicks",
				"LocalCost",
				"LocalImpressions",
				"PromotedImpressions",
				"StartDate",
				"EndDate",
			},
			Predicates: []gads.Predicate{
				{"CriterionId", "EQUALS", []string{criterionId}},
				{"AdGroupId", "EQUALS", []string{adGroupId}},
			},
		},
	)

	if err != nil {
		log.Fatal(err)
	}

	for _, bidLandscape := range criterionBidLandscape {
		landscapeJSON, _ := json.MarshalIndent(bidLandscape, "", "  ")
		fmt.Printf("%s\n", landscapeJSON)
	}

	// END Test GetCriterionBidLandscape

	// Test QueryCriterionBidLandscape

	queryCriterionBidLandscape, _, err := service.QueryCriterionBidLandscape(fmt.Sprintf("SELECT AdGroupId, Bid, CampaignId, CriterionId, LocalClicks, LocalCost, LocalImpressions WHERE AdGroupId = '%v' AND CriterionId = '%v'", adGroupId, criterionId))

	if err != nil {
		log.Fatal(err)
	}

	for _, bidLandscape := range queryCriterionBidLandscape {
		landscapeJSON, _ := json.MarshalIndent(bidLandscape, "", "  ")
		fmt.Printf("%s\n", landscapeJSON)
	}

	// END Test QueryCriterionBidLandscape

}
Ejemplo n.º 10
0
func main() {
	flag.Parse()
	config, err := gads.NewCredentialsFromFile(*configJson)
	if err != nil {
		log.Fatal(err)
	}

	// Batch Job
	bs := gads.NewBatchJobService(&config.Auth)

	/*ago := gads.AdGroupCriterionOperations{
	"SET":	gads.AdGroupCriterions {
				gads.BiddableAdGroupCriterion{
					AdGroupId: 11400713462,
					Criterion: gads.KeywordCriterion{
						Id: 47652524966,
					},
					BiddingStrategyConfiguration: &gads.BiddingStrategyConfiguration{
						Bids: []gads.Bid{
							gads.Bid{
								Type:   "CpcBid",
								Amount: 5372200,
							},
						},
					},
					UrlCustomParameters: gads.CustomParameters{
						CustomParameters: []gads.CustomParameter{
							gads.CustomParameter{
								Key:      "foo",
								Value:    "bar",
								IsRemove: false,
							},
						},
						DoReplace: false,
					},
				},
				gads.BiddableAdGroupCriterion{
					AdGroupId: 11400713462,
					Criterion: gads.KeywordCriterion{
						Id: 47652524366,
					},
					BiddingStrategyConfiguration: &gads.BiddingStrategyConfiguration{
						Bids: []gads.Bid{
							gads.Bid{
								Type:   "CpcBid",
								Amount: 5372200,
							},
						},
					},
					UrlCustomParameters: gads.CustomParameters{
						CustomParameters: []gads.CustomParameter{
							gads.CustomParameter{
								Key:      "foo",
								Value:    "bar",
								IsRemove: false,
							},
						},
						DoReplace: false,
					},
				},
			},
	}*/
	// Creating AdGroups
	ago := gads.AdGroupOperations{
		"ADD": {},
	}

	// stress test uploading
	var adGroupNum int = 10000

	for i := 0; i < adGroupNum; i++ {
		ago["ADD"] = append(ago["ADD"], gads.AdGroup{
			Name:       "test ad group " + rand_str(10),
			Status:     "PAUSED",
			CampaignId: campaignId,
		})
	}

	var operations []interface{}
	operations = append(operations, ago)

	bjo := gads.BatchJobOperations{
		BatchJobOperations: []gads.BatchJobOperation{
			gads.BatchJobOperation{
				Operator: "ADD",
				Operand:  gads.BatchJob{},
			},
		},
	}

	if resp, err := bs.Mutate(bjo); err == nil {

		bjh := gads.NewBatchJobHelper(&config.Auth)
		err = bjh.UploadBatchJobOperations(operations, *resp[0].UploadUrl)

		if err != nil {
			panic(err)
		}

		jobId := resp[0].Id
		batchJobs := gads.BatchJobPage{}

		// loop
		for {
			// recheck every 5 seconds
			time.Sleep(5 * time.Second)
			selector := gads.Selector{
				Fields: []string{
					"Id",
					"Status",
					"DownloadUrl",
					"ProcessingErrors",
					"ProgressStats",
				},
				Predicates: []gads.Predicate{
					{"Id", "EQUALS", []string{strconv.FormatInt(jobId, 10)}},
				},
			}

			// more than likely you'll want to have some logic to loop through these if you have multiple batch jobs, but since only one we just want to grab the first one
			batchJobs, err = bs.Get(selector)

			if err != nil {
				panic(err)
			}

			if batchJobs.BatchJobs[0].Status == "DONE" {
				break
			} else if batchJobs.BatchJobs[0].Status == "CANCELED" {
				panic("Job was canceled")
			}
		}

		if batchJobs.BatchJobs[0].DownloadUrl.Url != "" {
			// get the job
			mutateResult, err := bjh.DownloadBatchJob(*batchJobs.BatchJobs[0].DownloadUrl)

			if err != nil {
				panic(err)
			}

			fmt.Println(mutateResult)
			jsonResult, _ := json.Marshal(mutateResult)

			fmt.Println(string(jsonResult))
		}
	} else {
		// handle err
		panic(err)
	}

}