設定
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
構成は Config
クラスを使用して行います。このクラスには複数のバージョンからアクセスできます。
たとえば、構成ファイルの作成、作成時に値の指定、
値を読み込むことができます。
構成ファイル
1 対 1 の
google_ads_config.rb
クライアントをインスタンス化する際に使用するファイルを指定します。
インスタンス化時に引数を使用しない場合:
client = Google::Ads::GoogleAds::GoogleAdsClient.new
この場合、ライブラリは
GOOGLE_ADS_CONFIGURATION_FILE_PATH
環境変数。変数の値が
未設定の場合、ライブラリは HOME
ディレクトリでファイルを探します。
または、パスを指定することもできます。
client = Google::Ads::GoogleAds::GoogleAdsClient.new("path/to/file.rb")
その場合、クライアントはそのファイルパスでファイルを探します。
このファイルを生成する最も簡単な方法は、google_ads_config.rb
を
GitHub リポジトリを確認し、更新トークン、クライアント ID、
クライアント シークレットです。
動的構成
この構成は、ライブラリをインスタンス化する際に動的に設定できます。
あるいはその後も同様です。
client = Google::Ads::GoogleAds::GoogleAdsClient.new do |config|
config.client_id = 'INSERT_CLIENT_ID_HERE'
# ... more configuration
end
インスタンス化後に構成を変更することもできます。
client.configure do |config|
config.login_customer_id = 'INSERT_LOGIN_CUSTOMER_ID_HERE'
# ... more configuration
end
構成フィールド
Config
オブジェクトは、次のフィールドをサポートしています。
一般フィールド:
refresh_token
: OAuth 更新トークン。
client_id
: OAuth クライアント ID。
client_secret
: OAuth クライアント シークレット。
developer_token
: API にアクセスするための開発者トークン。
login_customer_id
: 詳しくは、
login-customer-id のドキュメントをご覧ください。
ロギング フィールド。詳しくは、ロギングガイドをご覧ください。
log_level
: ログに記録する最小ログレベルのメッセージ。たとえば
'DEBUG'
を指定すると、すべてのログメッセージが確実に表示されます。また、
'INFO'
では DEBUG メッセージが除外されますが、その他のメッセージはすべて表示されます。
log_target
: ログの出力先(STDERR
など)。
logger
: 独自のカスタム ロガーを指定します。これを指定すると、両方の広告が
log_level
と log_target
。
環境変数
クライアント ライブラリは、環境変数を使用して構成できます。
デフォルトで読み込まれるため、追加の呼び出しが必要になるため、
する必要があります。環境変数の一覧をご覧ください。
でサポート
。
環境変数を Config
に読み込むには、load_environment_config
を呼び出します。
client = Google::Ads::GoogleAds::GoogleAdsClient.new
client.load_environment_config
この関数が呼び出されるたびに、環境変数の現在の状態が
Config
にあるものがすべて上書きされます。こちらの
たとえば、デフォルトの構成を使用しても、固有の構成をオーバーライドできます。
環境変数を使用して値を指定することも、完全に
使用します。
Ruby では、すべてのライブラリでサポートされている環境変数に加え、
ライブラリには、次の 2 つの変数が追加されています。
GOOGLE_ADS_RUBY_LOG_LEVEL
: 上記の log_level
。
GOOGLE_ADS_RUBY_HTTP_PROXY
: HTTP プロキシを指定します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-21 UTC。
[null,null,["最終更新日 2025-08-21 UTC。"],[[["\u003cp\u003eGoogle Ads API configuration is handled by a \u003ccode\u003eConfig\u003c/code\u003e class, modifiable via configuration files, dynamic settings, or environment variables.\u003c/p\u003e\n"],["\u003cp\u003eYou can provide a \u003ccode\u003egoogle_ads_config.rb\u003c/code\u003e file path directly, set it using the \u003ccode\u003eGOOGLE_ADS_CONFIGURATION_FILE_PATH\u003c/code\u003e environment variable, or the library defaults to your home directory.\u003c/p\u003e\n"],["\u003cp\u003eDynamic configuration allows setting or updating values using blocks when instantiating or after creating the \u003ccode\u003eGoogle::Ads::GoogleAds::GoogleAdsClient\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eEnvironment variables offer another configuration approach, loaded by calling \u003ccode\u003eload_environment_config\u003c/code\u003e on the client instance, overriding existing settings.\u003c/p\u003e\n"],["\u003cp\u003eSupported configuration fields include OAuth credentials, developer token, login customer ID, logging preferences, and a proxy setting specific to the Ruby library.\u003c/p\u003e\n"]]],[],null,["# Configuration is done using a `Config` class. You can access this class in multiple\nways, such as writing a configuration file, specifying values on creation, or\nloading values from environment variables.\n\nConfiguration file\n------------------\n\nYou can specify a\n[`google_ads_config.rb`](https://github.com/googleads/google-ads-ruby/blob/HEAD/google_ads_config.rb)\nfile to use when instantiating the client.\n\nIf you use no arguments when instantiating: \n\n client = Google::Ads::GoogleAds::GoogleAdsClient.new\n\nthen the library will look in the location specified in the\n`GOOGLE_ADS_CONFIGURATION_FILE_PATH` environment variable. If that variable is\nnot set, then the library will look in your `HOME` directory for the file.\n\nAlternatively, you can specify a path: \n\n client = Google::Ads::GoogleAds::GoogleAdsClient.new(\"path/to/file.rb\")\n\nin which case the client will look for the file at that filepath.\n\nThe easiest way to generate this file is to copy the `google_ads_config.rb` from\nthe GitHub repository and modify it to include your refresh token, client ID,\nand client secret.\n\nDynamic configuration\n---------------------\n\nYou can set up the configuration dynamically when instantiating the library,\nor even afterwards: \n\n client = Google::Ads::GoogleAds::GoogleAdsClient.new do |config|\n config.client_id = 'INSERT_CLIENT_ID_HERE'\n # ... more configuration\n end\n\nYou can even modify the configuration after instantiation: \n\n client.configure do |config|\n config.login_customer_id = 'INSERT_LOGIN_CUSTOMER_ID_HERE'\n # ... more configuration\n end\n\nConfiguration fields\n--------------------\n\nThe `Config` object supports the following fields.\n\nGeneral fields:\n\n- `refresh_token`: Your OAuth refresh token.\n- `client_id`: Your OAuth client ID.\n- `client_secret`: Your OAuth client secret.\n- `developer_token`: Your developer token for accessing the API.\n- `login_customer_id`: See the [login-customer-id documentation](/google-ads/api/docs/concepts/call-structure#cid).\n\nLogging fields. See the [logging guide](/google-ads/api/docs/client-libs/ruby/logging) for complete details.\n\n- `log_level`: The minimum log level messages you want logged. For example, specifying `'DEBUG'` will ensure you see all log messages, and specifying `'INFO'` will exclude DEBUG messages but show all other messages.\n- `log_target`: Where you want to log to, such as `STDERR`.\n- `logger`: Specify your own custom logger. Specifying this will override both `log_level` and `log_target`.\n\nEnvironment variables\n---------------------\n\nYou can configure the client library using environment variables. They are not\nloaded by default, and require an additional call after instantiating the\nclient in order to load. See the complete list of [environment variables\nsupported by all\nlanguages](/google-ads/api/docs/client-libs#configuration).\n\nTo load the environment variables into your `Config`, call `load_environment_config`: \n\n client = Google::Ads::GoogleAds::GoogleAdsClient.new\n client.load_environment_config\n\nEach time this is called, the current state of the environment variables will\noverwrite anything that is already present in the `Config`. With this\nmechanism, you can for example have a default config but override specific\nvalues using environment variables, or you can entirely configure with\nenvironment variables.\n\nIn addition to the environment variables supported by all libraries, the Ruby\nlibrary has two additional variables:\n\n- `GOOGLE_ADS_RUBY_LOG_LEVEL`: As `log_level` above.\n- `GOOGLE_ADS_RUBY_HTTP_PROXY`: Specify an HTTP proxy."]]