google_ads_initialize
Set up the Google Ads API connection with OAuth credentials and developer token. Required before using any other Google Ads tools.
Instructions
Initialize the Google Ads API connection with OAuth credentials.
This must be called before using any other Google Ads tools. Provide your developer token, OAuth2 credentials, and optionally an MCC login customer ID if you're accessing client accounts.
Args: developer_token: API developer token client_id: OAuth2 client ID client_secret: OAuth2 client secret refresh_token: OAuth2 refresh token login_customer_id: Optional MCC account ID (without hyphens)
Returns: Confirmation message with initialization status
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| developer_token | Yes | ||
| client_id | Yes | ||
| client_secret | Yes | ||
| refresh_token | Yes | ||
| login_customer_id | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- utils/auth_manager.py:133-197 (helper)The initialize_oauth method on GoogleAdsAuthManager, called by the tool handler. It creates a TokenManager, validates the refresh token, builds credentials, creates the GoogleAdsClient, and stores the client session.
def initialize_oauth( self, developer_token: str, client_id: str, client_secret: str, refresh_token: str, login_customer_id: Optional[str] = None, client_key: str = "default" ) -> str: """ Initialize Google Ads client with OAuth2. Args: developer_token: Google Ads developer token client_id: OAuth2 client ID client_secret: OAuth2 client secret refresh_token: OAuth2 refresh token login_customer_id: Optional MCC account ID client_key: Unique identifier for this client session Returns: Client key for this session Raises: AuthenticationError: If initialization fails """ try: # Create token manager token_manager = TokenManager( client_id=client_id, client_secret=client_secret, refresh_token=refresh_token ) # Validate token if not token_manager.validate_token(): raise AuthenticationError("Invalid refresh token") # Build credentials dict credentials = { "developer_token": developer_token, "client_id": client_id, "client_secret": client_secret, "refresh_token": refresh_token, "use_proto_plus": True } if login_customer_id: credentials["login_customer_id"] = login_customer_id # Create client client = GoogleAdsClient.load_from_dict(credentials) # Store client and token manager self._clients[client_key] = client self._token_managers[client_key] = token_manager self._current_client_key = client_key logger.info(f"Google Ads client initialized: {client_key}") return client_key except Exception as e: logger.error(f"Failed to initialize OAuth client: {e}") raise AuthenticationError(f"OAuth initialization failed: {e}")