Posts tagged with google-ads-api

I hope this is in the correct section of the forum, if not an administrator can move the post to the correct place.

Our organization has an existing Google Adwords (G4) that currently a few members of our organization is using and administrating.

This instance of Google Adwords (G4) is currently not connected to our organization.

We want to setup SSO with Azure AD but for this to work the Adwords need to be connected to the organization.

How can we do this? Do we need to create a new google cloud organization and then integrate/connect it to the current Adwords - Or do we need to migrate everything to the new google cloud organization?

We have tried finding the answers for this in the Google Adwords account and in the Google Cloud organizational account, but have not found any information. Is there anyone that has done this or have any recommendations regarding this?

I tried to fetch GCLID using campaign_id but I'm not able to find it.

I've explore over a network but can't find any way to find GCLID.

Currently I've such type of data :-

{             "campaign": {                 "resourceName": "customers/{customer_id}/campaigns/{campaign_id}",                 "status": "ENABLED",                 "name": "campaign_name"             },             "ad_account": "ad_account_id"         } 

I want GCLID with the help of any of above fields

Or informed me if there any other fields required to get GCLID.

Actual Requirement :-I'm storing leads which is comes through google ads , in that data I've store GCLID from URL parameters of the landing page where the user lands after clicking on the ad.

Lead store such like this in my Database :-

{   "_id": "652d453sd46453f45"   "lead_id": "652a2bd489a65bf1ad53618a",   "url_parameters": {     "tactic_id": "5907417",     "utm_source": "google-adwords",     "utm_medium": "Campaign_medium",     "utm_campaign": "Campaign_Name",     "utm_term": "TERM",     "device": "c",     "matchtype": "p",     "network": "g",     "gclid": "GCLID",     "gad": "1/lead"   },   "current_url": "URL/?tactic_id=5907417&utm_source=google-adwords&utm_medium=[Campaign_medium]&utm_campaign=[Campaign_Name]&utm_term=customer%20management%20tools&device=c&matchtype=p&network=g&gclid=[GCLID]&gad=1/contact", } 

So I'm displaying campaign impressions, clicks , etc.. so here i want to show how many leads come through this campaign, so for this campaign first i've to find GCLID and then I'll fetch leads which is attributed in my DATABASE with the help of using this GCLID.

I am trying to pull data from Google Ads API to get campaign data without using OAuth Scopes and by just using a service account. Though I have put all the service account credential in my yaml file, I am getting "The Google account (@gmail.com user) that generated the OAuth access tokens is not associated with any Ads accounts." PLEASE HELP:)

CODE:

    from google.ads.googleads.client import GoogleAdsClient     from google.oauth2.service_account import Credentials     def get_campaigns_with_service_account(path_to_credential_file):   """Retrieves a list of campaigns using a service account.   Args:       client_id: The client ID of your Google Ads API credentials.       client_secret: The client secret of your Google Ads API credentials (optional).       refresh_token: The refresh token for your Google Ads API credentials (optional).       developer_token: The developer token for your Google Ads API project.       path_to_credential_file: The path to your service account key file in JSON format.   """   # Configure service account credentials   credentials = Credentials.from_service_account_file(       path_to_credential_file,       scopes=['https://www.googleapis.com/auth/adwords'],  # Adjust scopes as needed   )   # Create Google Ads client using service account credentials   client =GoogleAdsClient.load_from_storage("/content/drive/My Drive/Keys/google-ads.yaml")   ga_service = client.get_service("GoogleAdsService", version="v16")  # Use CampaignService   # Create a query to retrieve all campaigns   query = ("SELECT campaign.id, campaign.name, campaign.status "            "FROM campaign")   # Get a response with campaign information   customer_id = 'XXXXXX'  # Replace with your actual customer ID   def stream_response(client, customer_id, query):     return client.get_service("GoogleAdsService", version="v16").search_stream(customer_id=customer_id,       query=query)` ` 

MY YAML FILE:

`# Developer token ########################################################################################## # A developer token is required when making requests to the Google Ads API regardless of # # whether you're using the OAuth2 or Service Account configurations. To obtain a         # # developer token see:                                                                   # # https://developers.google.com/google-ads/api/docs/first-call/dev-token                 # ##########################################################################################     developer_token: {{token}} # Use proto plus ########################################################################################## # This parameter specifies whether the client library should return proto-plus messages  # # or protobuf messages. This value should be explicitly set to either "True" or "False", # # For more information on the differences between these two types, see our Protobuf      # # Messages guide:                                                                        # # https://developers.google.com/google-ads/api/docs/client-libs/python/protobuf-messages # ##########################################################################################     use_proto_plus: False # OAuth2 configuration ########################################################################################## # The below configuration parameters are used to authenticate using the recommended      # # OAuth2 flow. For more information on authenticating with OAuth2 see:                   # # https://developers.google.com/google-ads/api/docs/oauth/overview                       # ########################################################################################## #client_id: INSERT_ID_HERE #client_secret: INSERT_SECRET_HERE #refresh_token: INSERT_REFRESH_TOKEN_HERE # Service Account configuration ########################################################################################## # To authenticate with a service account add the appropriate values to the below         # # configuration parameters and remove the three OAuth2 credentials above. The            # # "json_key_file_path" value should be a path to your local private key json file, and   # # "impersonated_email" should be the email address that is being used to impersonate the # # credentials making requests. for more information on service accounts, see:            # # https://developers.google.com/google-ads/api/docs/oauth/service-accounts.              # # If you're authorizing with direct account access, then the "impersonated_email"        # # configuration is optional.                                                             # ##########################################################################################     json_key_file_path: /content/drive/My Drive/Keys/winged-woods-421416-bcf06a74b272.json     impersonated_email: api-creds@winged-woods-xxx.iam.gserviceaccount.com # Login customer ID configuration ########################################################################################## # Required for manager accounts only: Specify the login customer ID used to authenticate # # API calls. This will be the customer ID of the authenticated manager account. It       # # should be set without dashes, for example: 1234567890 instead of 123-456-7890. You can # # also specify this later in code if your application uses multiple manager account +    # # OAuth pairs.                                                                           # ########################################################################################## login_customer_id: XXXXXXXX # Logging configuration ########################################################################################## # Below you may specify the logging configuration. This will be provided as an input to  # # logging.config.dictConfig. Use the "level" block under the root logger configuration   # # to adjust the logging level. Note in the "format" field that log messages are          # # truncated to 5000 characters by default. You can change this to any length by removing # # the ".5000" portion or changing it to a different number.                              # # ######################################################################################## # logging:   # version: 1   # disable_existing_loggers: False   # formatters:     # default_fmt:       # format: '[%(asctime)s - %(levelname)s] %(message).5000s'       # datefmt: '%Y-%m-%d %H:%M:%S'   # handlers:     # default_handler:       # class: logging.StreamHandler       # formatter: default_fmt   # loggers:     # "":       # handlers: [default_handler]       # level: INFO # Proxy configuration ########################################################################################## # Below you can specify an optional proxy configuration to be used by requests. If you   # # don't have username and password, just specify host and port.                          # # ######################################################################################## # http_proxy: http://user:password@localhost:8000` 
 OUTPUT: FaultMessage: The Google account (@gmail.com user) that generated the OAuth access tokens is not associated with any Ads accounts. Create a new account, or add the Google account to an existing Ads account.   message: "The Google account (@gmail.com user) that generated the OAuth access tokens is not associated with any Ads accounts. Create a new account, or add the Google account to an existing Ads account." } 

i try to create an adgroup by REST api request. payload is this {"operations":[{"create":{"status":"ENABLED","name":"Adset","type":"DISPLAY_STANDARD","campaign":"customers/id/campaigns/id","optimizedTargetingEnabled":true,"audienceSetting":{"useAudienceGrouped":true}}}]}

{"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.ads.googleads.v14.errors.GoogleAdsFailure","errors":[{"errorCode":{"contextError":"OPERATION_NOT_PERMITTED_FOR_CONTEXT"},"message":"The operation is not allowed for the given context.","trigger":{"stringValue":"DISPLAY"},"location":{"fieldPathElements":[{"fieldName":"operations","index":0},{"fieldName":"create"},{"fieldName":"audience_setting"},{"fieldName":"use_audience_grouped"}]}}],"requestId":""}]}}

in Airbyte i have setup a source from Google Ads. The Client ID, Secret, Refresh Token is filled in. Then i input the CUSTOMER ID. Under this customer there are several Campaigns, but one Active one is missing in the final data that i receive from Airbyte.

Should i refresh the Client ID/Secret/Token or do i need to enable this missing Campaign in Google Ads?

I would assume that all campaigns should be automatically included if they are under the common Customer ID.

Thank you