Hello everyone, I'm developing application in Django and using client library for GoogleAds (google-ads). I have Manager account A for first email, and Test Manager account B with some Test Client accounts, testing was OK (using Web-app flow, retrieve refresh token and operate with Test Manager account B, using developer token from Manager account A).
Problem appeared, when I tried to access to another Test Manager account C with some customers, I have such error
errors {
error_code {
operation_access_denied_error: CREATE_OPERATION_NOT_PERMITTED
}
message: "Unauthorized CREATE operation in invoking a service\'s mutate method."
trigger {
string_value: "DISPLAY_SMART_CAMPAIGN"
}
location {
field_path_elements {
field_name: "operations"
index: 0
}
field_path_elements {
field_name: "create"
}
field_path_elements {
field_name: "advertising_channel_sub_type"
} }
}
Accessing account B with it customers did not cause that error, I decided that smith wrong with customers on Test Manager account C, because I have added Test Client from account B and it worked. Can you help me with that?
Runnable code
...
budget_resource_name = create_campaign_budget(
client=client, customer_id=customer_id, campaign=campaign
)
campaign_resource_name = create_campaign(
client=client, customer_id=customer_id, campaign=campaign, budget_name=budget_resource_name
)
...
def create_campaign_budget(client, customer_id: str, campaign: Campaign):
"""Adds a campaign budget to the given client account.
Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID str.
campaign: campaign instance (model)
Returns:
A str of the resource name for the newly created campaign budget.
"""
campaign_budget_operation = client.get_type("CampaignBudgetOperation")
campaign_budget = campaign_budget_operation.create
campaign_budget.name = f'CampaignBudget for Campaign #{campaign.pk}'
campaign_budget.amount_micros = int(campaign.daily_budget * 10_000 * 100)
campaign_budget.delivery_method = (
client.enums.BudgetDeliveryMethodEnum.STANDARD
)
campaign_budget.explicitly_shared = False
campaign_budget_service = client.get_service("CampaignBudgetService")
response = campaign_budget_service.mutate_campaign_budgets(
customer_id=customer_id, operations=[campaign_budget_operation]
)
resource_name = response.results[0].resource_name
campaign.google_budget_id = resource_name.split('/')[-1]
campaign.save()
return resource_name
def create_campaign(client, customer_id: str, campaign: Campaign, budget_name: str):
"""Adds a Display campaign to the given client account using the given budget.
Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID str.
campaign: campaign instance (model)
budget_name: the resource name str for a campaign budget.
Returns:
A str of the resource name for the newly created campaign.
"""
google_campaign_service = client.get_service("CampaignService")
google_campaign_operation = client.get_type("CampaignOperation")
google_campaign = google_campaign_operation.create
google_campaign.name = f'{campaign.name} #{campaign.pk}' # must be unique so add pk to name
advertising_channel_type_enum = client.enums.AdvertisingChannelTypeEnum
google_campaign.advertising_channel_type = advertising_channel_type_enum.DISPLAY
advertising_channel_sub_type_enum = (
client.enums.AdvertisingChannelSubTypeEnum
)
# Smart Display campaign requires the advertising_channel_sub_type as
# "DISPLAY_SMART_CAMPAIGN".
google_campaign.advertising_channel_sub_type = (
advertising_channel_sub_type_enum.DISPLAY_SMART_CAMPAIGN
)
status_enum = client.enums.CampaignStatusEnum
if config('GOOGLE_STATUS_AD') == 'ENABLED':
google_campaign.status = status_enum.ENABLED
else:
google_campaign.status = status_enum.PAUSED
# Smart Display campaign requires the TargetCpa bidding strategy.
google_campaign.maximize_conversions.target_cpa = False
google_campaign.campaign_budget = budget_name
# Target: Presence for geotargeting
presence_pos_type = client.enums.PositiveGeoTargetTypeEnum.PRESENCE
google_campaign.geo_target_type_setting.positive_geo_target_type = presence_pos_type
# Run dates
date_format = '%Y%m%d'
start_date, end_date = campaign.start_date, campaign.end_date
google_campaign.start_date = start_date.strftime(date_format)
google_campaign.end_date = end_date.strftime(date_format)
google_campaign_response = google_campaign_service.mutate_campaigns(
customer_id=customer_id, operations=[google_campaign_operation]
)
resource_name = google_campaign_response.results[0].resource_name
Interesting that throws error campaign creation, budget creation is OK. Thanks in advance, any help will be appreciated.