添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import com.google.ads.googleads.lib.GoogleAdsClient;
import com.google.ads.googleads.v15.errors.GoogleAdsException;
import com.google.ads.googleads.v15.services.GoogleAdsRow;
import com.google.ads.googleads.v15.services.GoogleAdsServiceClient;
import com.google.ads.googleads.v15.services.SearchGoogleAdsStreamRequest;
import com.google.ads.googleads.v15.services.SearchGoogleAdsStreamResponse;
import com.google.api.gax.rpc.ServerStream;

import java.io.FileNotFoundException;
import java.io.IOException;
public class GetCampaigns {

public static void main(String[] args) {
    GoogleAdsClient googleAdsClient = null;
    try {
        googleAdsClient = GoogleAdsClient.newBuilder().fromPropertiesFile().build();
    } catch (FileNotFoundException fnfe) {
        System.err.printf(
                "Failed to load GoogleAdsClient configuration from file. Exception: %s%n", fnfe);
        System.exit(1);
    } catch (IOException ioe) {
        System.err.printf("Failed to create GoogleAdsClient. Exception: %s%n", ioe);
        System.exit(1);
    runExample(googleAdsClient);
private static void runExample(GoogleAdsClient googleAdsClient) {
    try (GoogleAdsServiceClient googleAdsServiceClient =
                 googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
        String query = "SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id";
        SearchGoogleAdsStreamRequest request =
                SearchGoogleAdsStreamRequest.newBuilder()
                        .setCustomerId(Long.toString(9324397221L))
                        .setQuery(query)
                        .build();
        ServerStream<SearchGoogleAdsStreamResponse> stream =
                googleAdsServiceClient.searchStreamCallable().call(request);
        for (SearchGoogleAdsStreamResponse response : stream) {
            for (GoogleAdsRow googleAdsRow : response.getResultsList()) {
                System.out.printf(
                        "Campaign with ID %d and name '%s' was found.%n",
                        googleAdsRow.getCampaign().getId(), googleAdsRow.getCampaign().getName());

}