Note: The following explanation is for AdWords and Axis, but the general
idea applies to all products and frameworks.
The ads-lib artifact contains all of the library and utility classes for
accessing the Ads API, but does not support any specific SOAP framework. All
client library classes and utilities are in the package or sub-packages of
com.google.api.ads.common.lib. To add support for the AdWords API using the
Apache Axis framework, the adwords-axis plugin artifact is also necessary.
This artifact also includes autogenerated classes from the AdWords API. They
are in the package com.google.api.ads.adwords.{version}.
Getting started
Configure your project. You have multiple options for this step.
While we suggest using Maven, we understand that not all build environments
can handle this.
If using Maven with Eclipse
In the releases section
download a file like adwords-axis-maven-and-examples-v.vv.vv.tar.gz
and extract its contents to a directory.
Import the Eclipse project by going to File > Import, then General >
Existing projects into workspace and selecting the extracted folder.
If using Maven from the command line
In the releases section
download a file like adwords-axis-maven-and-examples-v.vv.vv.tar.gz
and extract its contents to a directory.
If using jars
In the releases section
download a file like adwords-axis-jars-and-examples-v.vv.vv.tar.gz and
extract its contents to a directory.
Copy the sample ads.properties file to your home directory and fill out
the required properties. You can skip the properties ending with clientId,
clientSecret, and refreshToken for now. You'll set those in the next
step.
Navigate in your project to any example (e.g.,
src/main/java/adwords/axis/v201809/basicoperations/GetCampaigns.java)
and run the example.
If using Maven from the command line
This command runs the GetAdGroups example, but you can update the
-Dexec.mainClass argument with the example of your choice.
Any parameters required for an example to run can be passed on the
command line by using -Dexec.args. To see more information about a
particular example, use -Dexec.args="--help".
Navigate in your project to any example (e.g.,
src/adwords/axis/v201809/basicoperations/GetCampaigns.java)
and run the example.
Basic usage
The following example is for AdWords and Axis, but the general code applies
to all products and frameworks.
// Contains the data classes and service classes.importcom.google.api.ads.adwords.axis.v201809.*;
importcom.google.api.ads.adwords.lib.client.AdWordsSession;
importcom.google.api.ads.adwords.lib.axis.factory.AdWordsServices;
publicstaticvoidmain(String[] args) throwsException {
/** * Create an AdWordsSession instance, loading credentials from the * properties file: */// Get an OAuth2 credential.Credentialcredential = newOfflineCredentials.Builder()
.forApi(OfflineCredentials.Api.AdWords)
.fromFile()
.build()
.generateCredential();
// Construct an AdWordsSession.AdWordsSessionsession = newAdWordsSession.Builder()
.fromFile()
.withOAuth2Credential(credential)
.build();
/** * Alternatively, you can specify your credentials in the constructor: */// Get an OAuth2 credential.credential = newOfflineCredentials.Builder()
.forApi(OfflineCredentials.Api.AdWords)
.withClientSecrets(clientId, clientSecret)
.withRefreshToken(refreshToken)
.build()
.generateCredential();
// Construct an AdWordsSession.session = newAdWordsSession.Builder()
.withDeveloperToken(developerToken)
// ...
.withOAuth2Credential(credential)
.build();
/** * Instantiate the desired service class using the AdWordsServices utility and * a Class object representing your service. */// Get the CampaignService.CampaignServiceInterfacecampaignService =
newAdWordsServices().get(session, CampaignServiceInterface.class);
/** * Create data objects and invoke methods on the service class instance. The * data objects and methods map directly to the data objects and requests for * the corresponding web service. */// Create selector.Selectorselector = newSelector();
selector.setFields(newString[] {"Id", "Name"});
// Get all campaigns.CampaignPagepage = campaignService.get(selector);
}
First, add an entry to your ads.properties file for each API you plan to use.
# AdWords
api.adwords.useCompression=true
# Ad Manager
api.admanager.useCompression=true
If using JaxWs, then no further steps are required.
If using Axis, then no further steps are required unless you are setting the
axis.ClientConfigFile system property. If you are setting
axis.ClientConfigFile to your own custom WSDD file and you want to use
compression, please ensure that the http transport defined in your WSDD
supports compression.
Using a proxy
It is recommended that the user set JVM arguments to configure this application
for their proxy.
https.proxyHost Hostname of proxy server web-proxy
https.proxyPort Port on server of proxy 8080
https.proxyUser Optional username for proxy authentication someone
https.proxyPassword Optional proxy server password secret
These properties can be set with JVM arguments in your Eclipse run
configuration:
The Keyword Optimizer application
is an open-source tool that uses the Google Ads APIs Client Library for Java
to find additional sets of keywords for Google Ads.
The AwReporting application is
an open-source application that uses the Google Ads APIs Client Library for
Java to download reports from multiple Google Ads accounts and store the
report contents in a database.
Where do I submit bug reports, feature requests and patches?
请发表评论