Wenn Sie sich mit anderen Nutzern über unsere Produkte austauschen und Feedback geben möchten, können Sie dem offiziellen Google Ads-Discord-Kanal auf dem Server der Google Advertising and Measurement Community beitreten.
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Die Google Ads API-Clientbibliothek für PHP bietet mehrere Konfigurationseinstellungen, mit denen Sie das Verhalten der Bibliothek anpassen können.
Konfigurationsdatei
Die meisten dieser Konfigurationseinstellungen können Sie in ini-Dateien speichern und beim Instanziieren von Clients verwenden, z. B. google_ads_php.ini.
Sowohl die Credential- als auch die Client-Builder bieten fromFile-Methoden zum Laden von Einstellungen aus solchen Dateien:
$oAuth2Credential = (new OAuth2TokenBuilder()) ->fromFile('/path/to/google_ads_php.ini') ->build();$googleAdsClient = (new GoogleAdsClientBuilder()) ->fromFile('/path/to/google_ads_php.ini') ->withOAuth2Credential($oAuth2Credential) ->build();
Wenn kein Konfigurationspfad als Argument angegeben wird, werden die fromFile-Methoden aus dem Standardkonfigurationspfad geladen:
Der Wert der Umgebungsvariable mit dem Namen GOOGLE_ADS_CONFIGURATION_FILE_PATH, falls festgelegt.
Andernfalls die google_ads_php.ini-Datei in Ihrem HOME-Verzeichnis.
$oAuth2Credential = (new OAuth2TokenBuilder()) ->fromFile() ->build();$googleAdsClient = (new GoogleAdsClientBuilder()) ->fromFile() ->withOAuth2Credential($oAuth2Credential) ->build();
Dynamische Konfiguration
Sie können diese Konfigurationseinstellungen dynamisch festlegen, wenn Sie Clients instanziieren.
$oAuth2Credential = (new OAuth2TokenBuilder()) ->withClientId('INSERT_CLIENT_ID') // ... ->build();$googleAdsClient = (new GoogleAdsClientBuilder()) ->withOAuth2Credential($oAuth2Credential) ->withDeveloperToken('INSERT_DEVELOPER_TOKEN_HERE') // ... ->build();
Konfigurationsumgebungsvariablen
Einige Konfigurationseinstellungen können beim Instanziieren von Clients über Umgebungsvariablen festgelegt werden (vollständige Liste).
Sowohl die Credential- als auch die Client-Builder bieten fromEnvironmentVariables-Methoden zum Laden von Einstellungen aus Umgebungsvariablen:
$oAuth2Credential = (new OAuth2TokenBuilder()) // ... ->fromEnvironmentVariables() ->build();$googleAdsClient = (new GoogleAdsClientBuilder()) ->withOAuth2Credential($oAuth2Credential) // ... ->fromEnvironmentVariables() ->build();
Felder für die Konfiguration
Die Konfigurationseinstellungen unterstützen mehrere Felder, die in Kategorien organisiert sind.
Von OAuth2TokenBuilder verwendete Felder:
App-Modus
[OAUTH2] clientId: Ihre OAuth2-Client-ID.
[OAUTH2] clientSecret: Ihr OAuth2-Clientschlüssel.
[OAUTH2] refreshToken: Ihr OAuth2-Aktualisierungstoken.
Dienstkontomodus
[OAUTH2] jsonKeyFilePath: Der Pfad zur JSON-Schlüsseldatei.
[OAUTH2] scopes: Die Bereiche.
[OAUTH2] impersonatedEmail: Die E-Mail-Adresse, deren Identität angenommen werden soll.
Von GoogleAdsClientBuilder verwendete Felder:
[GOOGLE_ADS] developerToken: Ihr Entwicklertoken für den Zugriff auf die API.
[GOOGLE_ADS] linkedCustomerId: Die verknüpfte Kunden-ID.
[LOGGING] logFilePath: Der Dateipfad für die Protokollierung.
[LOGGING] logLevel: Die Logging-Ebene.
[CONNECTION] proxy: Die Proxyserver-URL, die für die Internetverbindung verwendet wird.
[CONNECTION] transport: Das Transportmittel.
[CONNECTION] grpcChannelIsSecure: Gibt an, ob der gRPC-Channel sicher ist.
[CONNECTION] grpcChannelCredential: Die Anmeldedaten für den gRPC-Channel.
[CONNECTION] unaryMiddlewares: Die unären Middlewares.
[CONNECTION] streamingMiddlewares: Die Streaming-Middlewares.
[CONNECTION] grpcInterceptors: Die gRPC-Interceptors.
Konfigurationsprüfung
Die Konfigurationseinstellungen werden beim Instanziieren von Clients geprüft. Bei ungültigen Einstellungen werden Ausnahmen ausgelöst. Dafür gelten folgende Regeln:
[OAUTH2]-Felder dürfen nicht gleichzeitig für den Anwendungsmodus und den Dienstkontomodus festgelegt werden.
[OAUTH2] jsonKeyFilePath und [OAUTH2] scopes müssen festgelegt werden, wenn der Dienstkontomodus verwendet wird.
[OAUTH2] clientId, [OAUTH2] clientSecret und [OAUTH2] refreshToken müssen im Anwendungsmodus festgelegt werden.
[GOOGLE_ADS] developerToken muss immer festgelegt werden.
Wenn diese Werte festgelegt sind, müssen [GOOGLE_ADS] loginCustomerId und [GOOGLE_ADS] linkedCustomerId positive Zahlen sein.
Falls festgelegt, muss [CONNECTION] proxy eine gültige URL sein (siehe Filter FILTER_VALIDATE_URL).
Falls festgelegt, muss [LOGGING] logLevel ein gültiger PSR-Log-Level in Großbuchstaben sein, z. B. INFO.
Falls festgelegt, muss [CONNECTION] transport entweder grpc oder rest sein.
Wenn [CONNECTION] transport auf grpc gesetzt ist, muss der gRPC-Transport von der Umgebung unterstützt werden (siehe Anleitung transport).
[CONNECTION] grpcChannelIsSecure muss true sein, wenn [CONNECTION]
transport nicht auf grpc festgelegt ist.
[CONNECTION] grpcChannelCredential kann nur festgelegt werden, wenn [CONNECTION]
transport auf grpc gesetzt ist.
[CONNECTION] grpcChannelCredential kann nur festgelegt werden, wenn [CONNECTION]
grpcChannelIsSecuretrue ist.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-05 (UTC)."],[[["\u003cp\u003eThe Google Ads API PHP client library offers customizable configuration settings through INI files, dynamic settings, and environment variables.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage authentication using either Application Mode (client ID, secret, refresh token) or Service Account Mode (JSON key file).\u003c/p\u003e\n"],["\u003cp\u003eEssential settings include developer token, login customer ID, and optional proxy, logging, and transport configurations.\u003c/p\u003e\n"],["\u003cp\u003eConfiguration settings are validated upon client instantiation to ensure correctness and prevent errors.\u003c/p\u003e\n"],["\u003cp\u003eFor detailed information about specific configuration fields and their usage, refer to the provided documentation links.\u003c/p\u003e\n"]]],[],null,["# Configuration\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThe Google Ads API PHP client library provides several configuration settings that you\ncan use to customize the library behavior.\n\nConfiguration file\n------------------\n\nYou can store most of these configuration settings in\n[`ini`](//www.php.net/manual/en/function.parse-ini-file.php)\nfiles and use them when instantiating clients, for example,\n[`google_ads_php.ini`](https://github.com/googleads/google-ads-php/blob/HEAD/examples/Authentication/google_ads_php.ini).\n\nThe credential and client builders both provide `fromFile` methods to load\nsettings from such files: \n\n $oAuth2Credential = (new OAuth2TokenBuilder())\n -\u003efromFile('/path/to/google_ads_php.ini')\n -\u003ebuild();\n\n $googleAdsClient = (new GoogleAdsClientBuilder())\n -\u003efromFile('/path/to/google_ads_php.ini')\n -\u003ewithOAuth2Credential($oAuth2Credential)\n -\u003ebuild();\n\nIf there is no configuration path provided as argument, the `fromFile`\nmethods load from the default configuration path which is:\n\n1. The value of the environment variable named `GOOGLE_ADS_CONFIGURATION_FILE_PATH` if set.\n2. Otherwise, the `google_ads_php.ini` file in your `HOME` directory.\n\n $oAuth2Credential = (new OAuth2TokenBuilder())\n -\u003efromFile()\n -\u003ebuild();\n\n $googleAdsClient = (new GoogleAdsClientBuilder())\n -\u003efromFile()\n -\u003ewithOAuth2Credential($oAuth2Credential)\n -\u003ebuild();\n\nDynamic configuration\n---------------------\n\nYou can set these configuration settings dynamically when instantiating clients. \n\n $oAuth2Credential = (new OAuth2TokenBuilder())\n -\u003ewithClientId('INSERT_CLIENT_ID')\n // ...\n -\u003ebuild();\n\n $googleAdsClient = (new GoogleAdsClientBuilder())\n -\u003ewithOAuth2Credential($oAuth2Credential)\n -\u003ewithDeveloperToken('INSERT_DEVELOPER_TOKEN_HERE')\n // ...\n -\u003ebuild();\n\nConfiguration environment variables\n-----------------------------------\n\nYou can set some of the configuration settings from environment variables when\ninstantiating clients (see the [exhaustive\nlist](/google-ads/api/docs/client-libs#configuration)).\n\nThe credential and client builders both provide `fromEnvironmentVariables`\nmethods to load settings from environment variables:\n**Note:** Unset environment variables are *not* taken into account. \n\n $oAuth2Credential = (new OAuth2TokenBuilder())\n // ...\n -\u003efromEnvironmentVariables()\n -\u003ebuild();\n\n $googleAdsClient = (new GoogleAdsClientBuilder())\n -\u003ewithOAuth2Credential($oAuth2Credential)\n // ...\n -\u003efromEnvironmentVariables()\n -\u003ebuild();\n\nConfiguration fields\n--------------------\n\n| **Note:** The fields `grpcChannelCredential`, `unaryMiddlewares`, `streamingMiddlewares` and `grpcInterceptors` cannot be set from a configuration file or string but only dynamically.\n\nThe configuration settings support several fields organized in categories.\n\n1. Fields used by `OAuth2TokenBuilder`:\n - Application Mode\n - `[OAUTH2] clientId`: Your OAuth2 client ID.\n - `[OAUTH2] clientSecret`: Your OAuth2 client secret.\n - `[OAUTH2] refreshToken`: Your OAuth2 refresh token.\n - Service Account Mode\n - `[OAUTH2] jsonKeyFilePath`: The Json key file path.\n - `[OAUTH2] scopes`: The scopes.\n - `[OAUTH2] impersonatedEmail`: The email to impersonate.\n2. Fields used by `GoogleAdsClientBuilder`:\n - `[GOOGLE_ADS] developerToken`: Your developer token for accessing the API.\n - `[GOOGLE_ADS] loginCustomerId`: The [ID of the authorized\n customer](/google-ads/api/docs/concepts/call-structure#cid) to use in the request.\n - `[GOOGLE_ADS] linkedCustomerId`: The linked customer ID.\n - `[LOGGING] logFilePath`: The file path for logging.\n - `[LOGGING] logLevel`: The logging level.\n - `[CONNECTION] proxy`: The proxy server URL used for internet connectivity.\n - `[CONNECTION] transport`: The transport.\n - `[CONNECTION] grpcChannelIsSecure`: Whether the gRPC channel is secure or not.\n - `[CONNECTION] grpcChannelCredential`: The gRPC channel credentials.\n - `[CONNECTION] unaryMiddlewares`: The unary middlewares.\n - `[CONNECTION] streamingMiddlewares`: The streaming middlewares.\n - `[CONNECTION] grpcInterceptors`: The gRPC interceptors.\n\nConfiguration validation\n------------------------\n\nThe configuration settings are checked when instantiating clients and exceptions\nare thrown when invalid. Here are the rules:\n\n1. `[OAUTH2]` fields must not be set for both Application Mode and Service Account Mode at the same time.\n2. `[OAUTH2] jsonKeyFilePath` and `[OAUTH2] scopes` must be set when using the Service Account Mode.\n3. `[OAUTH2] clientId`, `[OAUTH2] clientSecret` and `[OAUTH2] refreshToken` must be set when using the Application Mode.\n4. `[GOOGLE_ADS] developerToken` must always be set.\n5. If set, `[GOOGLE_ADS] loginCustomerId` and `[GOOGLE_ADS] linkedCustomerId` must be positive numbers.\n6. If set, `[CONNECTION] proxy` must be a valid URL (see filter [FILTER_VALIDATE_URL](https://www.php.net/manual/en/filter.constants.php)).\n7. If set, `[LOGGING] logLevel` must be a valid [PSR log\n level](https://github.com/php-fig/log/blob/master/src/LogLevel.php) in capital-letters, such as `INFO`.\n8. If set, `[CONNECTION] transport` must be either `grpc` or `rest`.\n9. If `[CONNECTION] transport` is set to `grpc`, the gRPC transport must be supported by the environment (see guide [transport](/google-ads/api/docs/client-libs/php/transport)).\n10. `[CONNECTION] grpcChannelIsSecure` must be `true` when `[CONNECTION]\n transport` is not set to `grpc`.\n11. `[CONNECTION] grpcChannelCredential` can only be set when `[CONNECTION]\n transport` is set to `grpc`.\n12. `[CONNECTION] grpcChannelCredential` can only be set when `[CONNECTION]\n grpcChannelIsSecure` is `true`."]]