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
ss_name = "Google"

asset_service = client.get_service("AssetService")
# Add a marketing image
marketing_image = client.get_type("AdImageAsset")
marketing_image.asset = asset_service.asset_path(
customer_id, marketing_image_asset_id
)
responsive_display_ad.marketing_images.append(marketing_image)

# Add a square marketing image
square_marketing_image = client.get_type("AdImageAsset")
square_marketing_image.asset = asset_service.asset_path(
customer_id, square_marketing_image_asset_id
)
responsive_display_ad.square_marketing_images.append(square_marketing_image)

# Add the call to action
responsive_display_ad.call_to_action_text = "Shop Now"

# Add the price prefix
responsive_display_ad.price_prefix = "as low as"

# Add the promo text
responsive_display_ad.promo_text = "Free shipping!"

try:
ad_group_ad_response = ad_group_ad_service.mutate_ad_group_ads(
customer_id=customer_id, operations=[ad_group_ad_operation]
)
except GoogleAdsException as ex:
_handle_googleads_exception(ex)

return ad_group_ad_response.results[0].resource_name
# [END add_smart_display_ad_2]


def _handle_googleads_exception(exception):
print(
f'Request with ID "{exception.request_id}" failed with status '
f'"{exception.error.code().name}" and includes the following errors:'
)
for error in exception.failure.errors:
print(f'\tError with message "{error.message}".')
if error.location:
for field_path_element in error.location.field_path_elements:
print(f"\t\tOn field: {field_path_element.field_name}")
sys.exit(1)


if __name__ == "__main__":
# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
googleads_client = GoogleAdsClient.load_from_storage(version="v10",
path="C:/Users/Chiao/startinvest/prj17/google_ads_tutorials-master/creds_example/googleads.yaml")

parser = argparse.ArgumentParser(
description=(
"Creates a Smart Display campaign, and an ad group that "
"are then used to create a responsive display ad."
)
)
# The following argument(s) should be provided to run the example.
parser.add_argument(
"-c",
"--customer_id",
type=str,

help="The Google Ads customer ID.",
)
parser.add_argument(
"-m",
"--marketing_image_asset_id",
type=str,

help=("The ID for an image asset to be used as a marketing image."),
)
parser.add_argument(
"-s",
"--square_marketing_image_asset_id",
type=str,

help=(
"The resource name for an image asset to be used as a square "
"marketing image."
),
)
args = parser.parse_args()

main(
googleads_client,
"7199745982",
marketing_image_asset_id="40081329863",
square_marketing_image_asset_id="40080135580",
)

On Friday, May 27, 2022 at 10:34:56 AM UTC-7 Chiao Hsiao wrote:

> Hello,
> I am running the script of add_amart_display_ads.py, but I failed to do 
> the create operation as the following code:
>
> ---
> Created budget with resource name "customers/7199745982 <(719)%20974-5982>
> /campaignBudgets/10971713488".
> Request with ID "42zRfQLX_cfQvRh3hs_xLg" failed with status 
> "INVALID_ARGUMENT" and includes the following errors:
> Error with message "Unauthorized CREATE operation in invoking a 
> service's mutate method.".
> On field: operations
> On field: create
> On field: advertising_channel_sub_type
> Error with message "Conversion tracking is not enabled for the 
> campaign for VBB transition.".
> On field: operations
> On field: create
> On field: target_cpa
> Request made: ClientCustomerId: 7199745982 <(719)%20974-5982>, Host: 
> googleads.googleapis.com, Method: 
> /google.ads.googleads.v10.services.CampaignService/MutateCampaigns, 
> RequestId: 42zRfQLX_cfQvRh3hs_xLg, IsFault: True, FaultMessage: 
> Unauthorized CREATE operation in invoking a service's mutate method.
>
> 
> Note: I have the customer_Id, created in the test account, and all 
> credentials in googleads.yaml file, I can create another campaign such as 
> responsive search campaign successfully, so I think my customer_Id and all 
> credential in googleads.yaml file are correct, could you help me to solve 
> the problem?
>
> -
>
> The code below is my script:
> [image: 螢幕擷取畫面 202

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

2022-05-27 Thread Chiao Hsiao
Hello,
I am running the script of add_amart_display_ads.py, but I failed to do the 
create operation as the following code:
---
Created budget with resource name 
"customers/7199745982/campaignBudgets/10971713488".
Request with ID "42zRfQLX_cfQvRh3hs_xLg" failed with status 
"INVALID_ARGUMENT" and includes the following errors:
Error with message "Unauthorized CREATE operation in invoking a 
service's mutate method.".
On field: operations
On field: create
On field: advertising_channel_sub_type
Error with message "Conversion tracking is not enabled for the campaign 
for VBB transition.".
On field: operations
On field: create
On field: target_cpa
Request made: ClientCustomerId: 7199745982, Host: googleads.googleapis.com, 
Method: /google.ads.googleads.v10.services.CampaignService/MutateCampaigns, 
RequestId: 42zRfQLX_cfQvRh3hs_xLg, IsFault: True, FaultMessage: 
Unauthorized CREATE operation in invoking a service's mutate method.

Note: I have the customer_Id, created in the test account, and all 
credentials in googleads.yaml file, I can create another campaign such as 
responsive search campaign successfully, so I think my customer_Id and all 
credential in googleads.yaml file are correct, could you help me to solve 
the problem?
-

The code below is my script:
[image: 螢幕擷取畫面 2022-05-27 103050.png]
#!/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.
"""Adds a display upload ad to a given ad group.
To get ad groups, run get_ad_groups.py.
"""


import argparse
import sys

import requests

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


BUNDLE_URL = "https://gaagl.page.link/ib87;


def main(client, customer_id, ad_group_id):
"""Adds a display upload ad to a given ad group.
Args:
client: An initialized Google Ads client.
customer_id: The Google Ads customer ID.
ad_group_id: The ID of the ad group to which the new ad will be added.
"""
# There are several types of display upload ads. For this example, we will
# create an HTML5 upload ad, which requires a media bundle.
# This feature is only available to allowlisted accounts.
# See https://support.google.com/google-ads/answer/1722096 for more details.
# The DisplayUploadProductType field lists the available display upload 
types:
# 
https://developers.google.com/google-ads/api/reference/rpc/latest/DisplayUploadAdInfo

# Creates a new media bundle asset and returns the resource name.
ad_asset_resource_name = _create_media_bundle_asset(client, customer_id)

# Creates a new display upload ad and associates it with the specified
# ad group.
_create_display_upload_ad_group_ad(
client, customer_id, ad_group_id, ad_asset_resource_name
)


def _create_media_bundle_asset(client, customer_id):
"""Creates a media bundle from the assets in a zip file.
The zip file contains the HTML5 components.
Args:
client: An initialized Google Ads client.
customer_id: The Google Ads customer ID for which the call is made.
Returns:
The string resource name of the newly uploaded media bundle.
"""
# Get the AssetService client.
asset_service = client.get_service("AssetService")

# Construct an asset operation and populate its fields.
asset_operation = client.get_type("AssetOperation")
media_bundle_asset = asset_operation.create
media_bundle_asset.type_ = client.enums.AssetTypeEnum.MEDIA_BUNDLE
media_bundle_asset.name = "Ad Media Bundle"
# The HTML5 zip file contains all the HTML, CSS, and images needed for the
# HTML5 ad. For help on creating an HTML5 zip file, check out Google Web
# Designer (https://www.google.com/webdesigner/).
# Download the ZIP as bytes from the URL
media_bundle_asset.media_bundle_asset.data = requests.get(
BUNDLE_URL
).content

# Adds the asset to the client account.
mutate_asset_response = asset_service.mutate_assets(
customer_id=customer_id, operations=[asset_operation]
)

# Display and return the resulting resource name.
uploaded_asset_resource_name = mutate_asset_response.results[
0
].resource_name
print(f"Uploaded