Posts tagged with python

Here's what I've done. I'm using Python programming language.

res = requests.put(     url='https://graph.facebook.com/v13.0/messages/wamid.HBgMOTE4NzgwNDk1ODA0FQIAEhggQkU2OURGQUYyMzdCNDlBRkQ1QUI4RERBNDdENDBBOEIA',      header = {         "Authorization": "Bearer my-auth-token",         "Content-Type": "application/json"     },      data=json.dumps({"status": "read"}) ) print(res.json()) 

Output:

{'error': {'message': 'Unknown path components: /wamid.HBgMOTE4NzgwNDk1ODA0FQIAEhggQkU2OURGQUYyMzdCNDlBRkQ1QUI4RERBNDdENDBBOEIA', 'type': 'OAuthException', 'code': 2500, 'fbtrace_id': 'A6f8nCvHOSXSZcAGmevCGeJ'}} 

I need to import pandas and google ads in the AWS lambda function. pandas support only the 3.7 version and google ads support only the 3.8 version.

When I've given lambda 3.8 version google ads works and pandas get an error and when I'm given lambda 3.7 version pandas works and google ads get an error.

Please guide me on how to support the two versions of layers.

I need to make inactive assets linked to a specific ad, i.e. to get the same result through the api as in the google ads web interface. Example by following the link

I've tried it myself in two ways

  1. I wanted to try and delete the asset itself, but I found a description in the documentation that the asset cannot be deleted using AssetService because it does not support a remove operation
  2. Ok, I tried to remove an ad using AdGroupAdService using sample (using python but this is not crucial) but got an message about this operation not for an ad with type APP_AD message: "Cannot remove an adgroup ad with this ad type."

In the end, I found information that in order to stop an asset, the link between the asset and the ad has to be removed. But nowhere is there any example of what this is or how to do it. Any help with this problem would be greatly appreciated.

typicallyl in sql, you can use * to mutiply columns, but I am getting an error when trying to do so in my query below within GoogleAds API - anyone face this challenge before.

Code:

import sys, json, io, gzip, sys, os from googleads import adwords import pandas as pd import numpy as np def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):   ga_service = client.get_service("GoogleAdsService")   search_request=client.get_type("SearchGoogleAdsStreamRequest")   search_request.customer_id = customer_id     query = """         SELECT           segments.date,           ad_group.id,           ad_group.name,           campaign.id,           campaign.name,           metrics.impressions,           metrics.clicks,           metrics.clicks*metrics.average_cpc as cost,           metrics.conversions,           metrics.ctr,           metrics.average_cpc,           metrics.cost_per_conversion         FROM ad_group         where segments.date BETWEEN 20220427 AND 20220428                   limit 10         """                 print(query)   search_request.query = query      stream = ga_service.search_stream(search_request)      for batch in stream:     for row in batch.results:       print(row)         return 1 

Error:

Request made: , Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId: TevDX_z7WYF-AWUZBMVbnw, IsFault: True, FaultMessage: Error in query: unexpected input *. Traceback (most recent call last): 

Google Ads API recently discontinued an old version - https://ads-developers.googleblog.com/2021/04/upgrade-to-google-ads-api-from-adwords.html.

That being said I am trying to adjust my query to new api standards, and getting the strangest error "unexpected input DURING" -- more detail below. It would seem to be correct per this doc:https://developers.google.com/google-ads/api/docs/samples/get-hotel-ads-performance

Note the use of "DURING" in the example SQL query in the doc above.

Below is my error message and further below is script:

ERROR:

SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428 Request made: ClientCustomerId:, Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId:, IsFault: True, FaultMessage:  Error in query: unexpected input DURING. 

script:

import sys, json, io, gzip, sys, os from googleads import adwords import pandas as pd import numpy as np def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):   ga_service = client.get_service("GoogleAdsService")   search_request=client.get_type("SearchGoogleAdsStreamRequest")   search_request.customer_id = customer_id   query = f"SELECT {', '.join(str(x) for x in fields)} FROM {str(report_type[0])} WHERE Status IN {*statuses,} DURING {date_range}"      # query = "SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428"                 print(query)   search_request.query = query      stream = ga_service.search_stream(search_request)      for batch in stream:     for row in batch.results:       print(row)         return 1