GAPIC

src/Google/Ads/GoogleAds/vX içindeki kaynak kodu Google Ads API PHP istemci kitaplığının dizini (burada X, Google Ads API'dir) sürümü, GAPIC (Oluşturulan API İstemcisi) kullanılarak otomatik olarak oluşturulur Yayınlananlara göre oluşturucu proto dosyaları kullanabilirsiniz.

Oluşturulan kaynak kod daha sonra, GoogleAdsClientBuilder::build() çağrısı yapılarak oluşturulan GoogleAdsClient sınıfını kullanarak Google Ads API ile çalışan hizmet istemcileri oluşturmak için gereken özelliklere ve sınıflara referanslar içerecek şekilde değiştirilir. Hem GoogleAdsClient hem de GoogleAdsClientBuilder şu konumda manuel olarak oluşturulmuş sınıflardır: src/Google/Ads/GoogleAds/Lib/vX/.

Oluşturulan sınıf konumları

Son işleme tabi tutulan hizmet istemcileri src/Google/Ads/GoogleAds/VX/Services/Client/ içinde bulunur.

Kullanım

Bir istek nesnesi oluşturmanız ve bunu kullanmak istediğiniz istemciye iletmeniz gerekir. Bazı durumlarda, istek nesnesi oluşturmak için birden fazla yöntem kullanabilirsiniz. Çünkü bazı müşteriler, verileri aktarmak için build() adlı kullanışlı bir yönteme de sahiptir. zorunlu parametreler.

Örnek 1.1: Gerekli parametrelere sahip yöntemler

Aşağıdaki örnek kodda, CampaignService::mutate() işlevinin nasıl çağrılacağı gösterilmektedir. Tüm parametreler ($customerId ve $operations) zorunlu parametre olduğundan kodda her iki parametreyi de kabul eden build() oluşturulur.

Desen 1

$campaignServiceClient
    = $googleAdsClient->getCampaignServiceClient();
$response = $campaignServiceClient->mutateCampaigns(
    MutateCampaignsRequest::build(
      $customerId,
      $campaignOperations
    )
);

Desen 2

$campaignServiceClient
    = $googleAdsClient->getCampaignServiceClient();
$request = (new MutateCampaignsRequest())
    ->setCustomerId($customerId)
    ->setCampaignOperations($campaignOperations);
$response = $campaignServiceClient->mutateCampaigns($request);

Örnek 1.2: Gerekli parametreler ve isteğe bağlı parametreler içeren yöntemler

Aşağıdaki örnek kodda GoogleAdsServiceClient::search() çağrılıyor. Burada Örneğin, kodda oluşturulan build() yalnızca iki parametreyi kabul eder ($customerId ve $query) zorunlu parametre oldukları için. LIMIT ifadesini yoksayarak sorguyla eşleşen toplam sonuç sayısını setReturnTotalResultsCount() kullanarak açıkça ayarlamanız gerekir. Alternatif olarak: tüm parametreleri SearchGoogleAdsRequest değerini girin.

Desen 1

$googleAdsServiceClient
    = $googleAdsClient->getGoogleAdsServiceClient();
$response = $googleAdsServiceClient->search(
    SearchGoogleAdsRequest::build($customerId, $query)
        ->setReturnTotalResultsCount(true)
);

Desen 2

$googleAdsServiceClient
    = $googleAdsClient->getGoogleAdsServiceClient();
$request = (new SearchGoogleAdsRequest())
    ->setCustomerId($customerId)
    ->setQuery($query)
    ->setReturnTotalResultsCount(true);
$response = $googleAdsServiceClient->search($request);

Desen 3

$googleAdsServiceClient
    = $googleAdsClient->getGoogleAdsServiceClient();
$request = (new SearchGoogleAdsRequest([
    'customer_id' => $customerId,
    'query' => $query,
    'return_total_results_count' => true
]);
$response = $googleAdsServiceClient->search($request);

2. Örnek: Yalnızca isteğe bağlı parametreleri olan yöntemler

Bu örnekte, nasıl arama yapacağınız gösterilmektedir GeoTargetConstantServiceClient::suggestGeoTargetConstants() GeoTargetConstantServiceClient::suggestGeoTargetConstants() parametrelerinin tümü isteğe bağlı olduğundan bu durumda build() kaynak kodda oluşturulmaz. İstekte bulunma nesnesini kendiniz oluşturmanız gerekir.

Desen 1

$geoTargetConstantServiceClient =
    $googleAdsClient->getGeoTargetConstantServiceClient();
$request = (new SuggestGeoTargetConstantsRequest())
    ->setLocale($locale)
    ->setCountryCode($countryCode)
    ->setLocationNames(new LocationNames(['names' => $locationNames]));
$response =
    $geoTargetConstantServiceClient->suggestGeoTargetConstants($request);

Desen 2

$geoTargetConstantServiceClient =
    $googleAdsClient->getGeoTargetConstantServiceClient();
$response = $geoTargetConstantServiceClient->suggestGeoTargetConstants(
    new SuggestGeoTargetConstantsRequest([
        'locale' => $locale,
        'country_code' => $countryCode,
        'location_names' => new LocationNames(['names' => $locationNames])
    ])
);