Load data from Google Ads Stay organized with collections Save and categorize content based on your preferences.
Schedule recurring load jobs from Google Ads (formerly known as Google AdWords) into BigQuery.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Java
Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
importcom.google.api.gax.rpc.ApiException;importcom.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest;importcom.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient;importcom.google.cloud.bigquery.datatransfer.v1.ProjectName;importcom.google.cloud.bigquery.datatransfer.v1.TransferConfig;importcom.google.protobuf.Struct;importcom.google.protobuf.Value;importjava.io.IOException;importjava.util.HashMap;importjava.util.Map;// Sample to create ads(formerly AdWords) transfer configpublicclassCreateAdsTransfer{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.finalStringprojectId="MY_PROJECT_ID";StringdatasetId="MY_DATASET_ID";// the customer_id only allows digits and hyphen ('-').StringcustomerId="012-345-6789";StringrefreshWindow="100";Map<String,Value>params=newHashMap<>();params.put("customer_id",Value.newBuilder().setStringValue(customerId).build());params.put("refreshWindow",Value.newBuilder().setStringValue(refreshWindow).build());TransferConfigtransferConfig=TransferConfig.newBuilder().setDestinationDatasetId(datasetId).setDisplayName("Your Ads Transfer Config Name").setDataSourceId("adwords").setParams(Struct.newBuilder().putAllFields(params).build()).build();createAdsTransfer(projectId,transferConfig);}publicstaticvoidcreateAdsTransfer(StringprojectId,TransferConfigtransferConfig)throwsIOException{try(DataTransferServiceClientclient=DataTransferServiceClient.create()){ProjectNameparent=ProjectName.of(projectId);CreateTransferConfigRequestrequest=CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).build();TransferConfigconfig=client.createTransferConfig(request);System.out.println("Ads transfer created successfully :"+config.getName());}catch(ApiExceptionex){System.out.print("Ads transfer was not created."+ex.toString());}}}What's next
To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.