Exemplo n.º 1
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)
}
Exemplo n.º 2
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)
	}

}
Exemplo n.º 3
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)
}
Exemplo n.º 4
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)
	}

}
Exemplo n.º 5
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)

}
Exemplo n.º 6
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)
	}

}