Re: Receive "Unauthorized CREATE operation in invoking a service's mutate method." error for add_amart_display_ads.py

2022-05-31 Thread Chiao Hsiao
Sorry for that the code above is the error of add_display_upload_ad.py,
and the code below is my code of add_smart_display_ads.py:

---
#!/usr/bin/env python
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This adds a smart display campaign, an ad group, and a responsive 
display ad.
More information about Smart Display campaigns can be found at:
https://support.google.com/google-ads/answer/7020281
IMPORTANT: The AssetService requires you to reuse what you've uploaded
previously. Therefore, you cannot create an image asset with the exactly 
same
bytes. In case you want to run this example more than once, note down the
created assets' resource names and specify them as command-line arguments 
for
marketing and square marketing images.
Alternatively, you can modify the image URLs' constants directly to use 
other
images. You can find image specifications in the pydoc for
ResponsiveDisplayAdInfo in common/ad_type_infos_pb2.py.
"""


import argparse
import datetime
import requests
import sys
from uuid import uuid4

from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException


_DATE_FORMAT = "%Y%m%d"
_MARKETING_IMAGE_URL = "https://gaagl.page.link/Eit5;
_MARKETING_IMAGE_WIDTH = 600
_MARKETING_IMAGE_HEIGHT = 315
_SQUARE_MARKETING_IMAGE_URL = "https://gaagl.page.link/bjYi;
_SQUARE_MARKETING_IMAGE_SIZE = 512


def main(
client,
customer_id,
marketing_image_asset_id=None,
square_marketing_image_asset_id=None,
):
budget_resource_name = _create_budget(client, customer_id)
print(f'Created budget with resource name "{budget_resource_name}".')

campaign_resource_name = _create_smart_display_campaign(
client, customer_id, budget_resource_name
)
print(
"Created smart display campaign with resource name "
f'"{campaign_resource_name}".'
)

ad_group_resource_name = _create_ad_group(
client, customer_id, campaign_resource_name
)
print(f'Created ad group with resource name "{ad_group_resource_name}"')

if marketing_image_asset_id:
print(
"Using existing marketing image asset with ID "
f'"{marketing_image_asset_id}".'
)
else:
marketing_image_asset_id = _upload_image_asset(
client,
customer_id,
_MARKETING_IMAGE_URL,
_MARKETING_IMAGE_WIDTH,
_MARKETING_IMAGE_HEIGHT,
"Marketing Image",
)
print(
"Created marketing image asset with ID "
f'"{marketing_image_asset_id}".'
)

if square_marketing_image_asset_id:
print(
"Using existing square marketing image asset with ID "
f'"{square_marketing_image_asset_id}".'
)
else:
square_marketing_image_asset_id = _upload_image_asset(
client,
customer_id,
_SQUARE_MARKETING_IMAGE_URL,
_SQUARE_MARKETING_IMAGE_SIZE,
_SQUARE_MARKETING_IMAGE_SIZE,
"Square Marketing Image",
)
print(
"Created square marketing image asset with ID "
f'"{square_marketing_image_asset_id}".'
)

responsive_display_ad_resource_name = _create_responsive_display_ad(
client,
customer_id,
ad_group_resource_name,
marketing_image_asset_id,
square_marketing_image_asset_id,
)
print(
"Created responsive display ad with resource name "
f'"{responsive_display_ad_resource_name}".'
)

print(
"Created responsive display ad with resource name "
f'"{responsive_display_ad_resource_name}".'
)


# [START add_smart_display_ad]
def _create_budget(client, customer_id):
campaign_budget_operation = client.get_type("CampaignBudgetOperation")
campaign_budget = campaign_budget_operation.create
campaign_budget.name = f"Interplanetary Cruise Budget #{uuid4()}"
campaign_budget.delivery_method = (
client.enums.BudgetDeliveryMethodEnum.STANDARD
)
campaign_budget.amount_micros = 50

campaign_budget_service = client.get_service("CampaignBudgetService")

try:
campaign_budget_response = (
campaign_budget_service.mutate_campaign_budgets(
customer_id=customer_id, operations=[campaign_budget_operation]
)
)
except GoogleAdsException as ex:
_handle_googleads_exception(ex)

return campaign_budget_response.results[0].resource_name
# [END add_smart_display_ad]


# [START add_smart_display_ad_1]
def _create_smart_display_campaign(client, customer_id, 
budget_resource_name):
campaign_service = client.get_service("CampaignService")
campaign_operation = client.get_type("CampaignOperation")
campaign = campaign_operation.create
campaign.name = f"Smart Display Campaign #{uuid4()}"
advertising_channel_type_enum = 

RE: Receive "Unauthorized CREATE operation in invoking a service's mutate method." error for add_amart_display_ads.py

2022-05-30 Thread 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum
Hi Chiao,

Thank you for raising your concern to this forum.

So that our team can investigate the issue further, could you provide the 
complete request and response logs with request ID and request header generated 
on your end in the format that you can see the provided links where we can see 
the error? This information in the preferred format can be extracted when 
logging of the API transactions is enabled on your end. To enable it, you can 
follow this guide for the Python client library.

You can provide it via Reply privately to author option. If this option is not 
available, then send it instead on this email address 
googleadsapi-supp...@google.com.

Regards,

Ernie John
Google Ads API Team
ref:_00D1U1174p._5004Q2bEKVf:ref

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/33aZT0RCPXN200nZui97BIRlmh_QTb9aYOOg%40sfdc.net.