Hello,
we are having problems with our python script for uploading extension -
sitelinks for campaigns, the script was running just fine until last week,
here is the code of functions, as well as the thrown ERROR below:
def main(client, customer_id, connection):
"""Adds sitelinks to a campaign using assets.
Args:
client: The Google Ads client.
customer_id: The customer ID for which to add the keyword.
campaign_id: The campaign to which sitelinks will be added.
"""
# select_docs = f"""SELECT `id`, `doctor_id` FROM `doctors-promoted` WHERE
`merged_account` = 6 AND 'm' NOT IN (SELECT `ext_sitelink` FROM
`aw_mp_campaigns` WHERE `doctor_id` = `doctors-promoted`.`doctor_id`)"""
#mixed
select_docs = f"""SELECT `id`, `doctor_id` FROM `doctors-promoted` WHERE
'n' IN (SELECT `ext_sitelink` FROM `aw_mp_campaigns` WHERE `doctor_id` =
`doctors-promoted`.`doctor_id`) AND `is_sbox` = 'y'"""
try:
select_docs_response = execute_read_query(connection, select_docs)
except Error as ex:
print("DB ERROR OCCURRED:")
print(ex.msg)
sys.exit(1)
for item in select_docs_response:
select_url = f"""SELECT `final_url` FROM `doctors-active` WHERE `doctor_id`
= {item[1]}"""
try:
select_url_response = execute_read_query(connection, select_url)
except Error as ex:
print("DB ERROR OCCURRED:")
print(ex.msg)
sys.exit(1)
resource_names = _create_sitelink_assets(client, customer_id,
select_url_response[0][0])
select_campaigns = f"""SELECT `id`, `aw_id` FROM `aw_mp_campaigns` WHERE
`doctor_id` = {item[1]} AND `name` LIKE '%[%'"""
try:
select_campaigns_response = execute_read_query(connection, select_campaigns)
except Error as ex:
print("DB ERROR OCCURRED:")
print(ex.msg)
sys.exit(1)
for sub in select_campaigns_response:
_link_sitelinks_to_campaign(
client, customer_id, sub[1], resource_names
)
update_campaign_in_db= f"""UPDATE `aw_mp_campaigns` SET `ext_sitelink` =
'y' WHERE `id` = {sub[0]}"""
try:
execute_query(connection, update_campaign_in_db)
except Error as ex:
print("DB ERROR OCCURRED:")
print(ex.msg)
sys.exit(1)
# Creates sitelink assets.
# Associates the sitelinks at the campaign level.
def _create_sitelink_assets(client, customer_id, doc_url):
"""Creates sitelink assets, which can be added to campaigns.
Args:
client: The Google Ads client.
customer_id: The customer ID for which to add the keyword.
campaign_id: The campaign to which sitelinks will be added.
Returns:
a list of sitelink asset resource names.
"""
sitelink1_operation = client.get_type("AssetOperation")
sitelink1_asset = sitelink1_operation.create
url1 = doc_url + "#tab=profile-info"
sitelink1_asset.final_urls.append(url1)
sitelink1_asset.sitelink_asset.link_text = "Consultórios"
sitelink2_operation = client.get_type("AssetOperation")
sitelink2_asset = sitelink2_operation.create
url2 = doc_url + "#tab=profile-pricing"
sitelink2_asset.final_urls.append(url2)
sitelink2_asset.sitelink_asset.link_text = "Serviços"
sitelink3_operation = client.get_type("AssetOperation")
sitelink3_asset = sitelink3_operation.create
url3 = doc_url + "#tab=profile-experience"
sitelink3_asset.final_urls.append(url3)
sitelink3_asset.sitelink_asset.link_text = "Experiência"
asset_service = client.get_service("AssetService")
response = asset_service.mutate_assets(
customer_id=customer_id,
operations=[
sitelink1_operation,
sitelink2_operation,
sitelink3_operation,
],
)
resource_names = [result.resource_name for result in response.results]
for resource_name in resource_names:
print(f"Created sitelink asset with resource name '{resource_name}'.")
return resource_names
def _link_sitelinks_to_campaign(
client, customer_id, campaign_id, resource_names
):
"""Creates sitelink assets, which can be added to campaigns.
Args:
client: The Google Ads client.
customer_id: The customer ID for which to add the keyword.
campaign_id: The campaign to which sitelinks will be added.
resource_names: a list of sitelink asset resource names.
"""
campaign_service = client.get_service("CampaignService")
operations = []
for resource_name in resource_names:
operation = client.get_type("CampaignAssetOperation")
campaign_asset = operation.create
campaign_asset.asset = resource_name
campaign_asset.campaign = campaign_service.campaign_path(
customer_id, campaign_id
)
campaign_asset.field_type = client.enums.AssetFieldTypeEnum.SITELINK
operations.append(operation)
campaign_asset_service = client.get_service("CampaignAssetService")
response = campaign_asset_service.mutate_campaign_assets(
customer_id=customer_id, operations=operations
)
for result in response.results:
print(
"Linked sitelink to campaign with resource name '{result.resource_name}'."
)
ERROR:
Request made: ClientCustomerId: 2611122037, Host: googleads.googleapis.com,
Method:
/google.ads.googleads.v9.services.CampaignAssetService/MutateCampaignAssets,
RequestId: K7VMZSMq6kPosrj8gnRfsw, IsFault: True, FaultMessage: This
request would exceed a limit on the number of allowed resources. The
details of which type of limit was exceeded will eventually be returned in
ErrorDetails. Request with ID 'K7VMZSMq6kPosrj8gnRfsw' failed with status
'INVALID_ARGUMENT' and includes the following errors: Error with message
'This request would exceed a limit on the number of allowed resources. The
details of which type of limit was exceeded will eventually be returned in
ErrorDetails.'. On field: operations
Thanks for your help.
Best,
Luka
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/3e451788-7d0f-4602-9432-7ad2e13acc02n%40googlegroups.com.