I am trying to access the metrics for client accounts using the Google Ads API, through the Python client.
Currently I'm using a modified version of the get_campaign_stats_to_csv.py
example, with the query:
import datetime
last_three_days = datetime.datetime.today() - datetime.timedelta(days=3)
query = """
SELECT
customer.descriptive_name,
metrics.cost_micros
FROM customer
WHERE
segments.date > '{last_three_days}'
AND segments.date <= '{today}'""".format(
last_three_days=last_three_days.strftime('%Y-%m-%d'),
today=datetime.datetime.today().strftime('%Y-%m-%d'))
It requires the commandline argument --customer_id=
of the account we're reporting on, used as follows:
search_request.customer_id = customer_id # e.g., '--customer_id=1234567890'
The problem is that when I use my Manager account customer id 1234567890
, I get the error:
error_code {
query_error: REQUESTED_METRICS_FOR_MANAGER
}
message: "Metrics cannot be requested for a manager account. To retrieve metrics, issue
separate requests against each client account under the manager account."
}
Which I assume means using the client id. But when I use the client ID 0987654321
, I get the error:
error_code {
authorization_error: USER_PERMISSION_DENIED
}
message: "User doesn\'t have permission to access customer. Note: If you\'re accessing a
client customer, the manager\'s customer id must be set in the \'login-customer-id\'
header. See https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid"
}
The link in the error message leads to the following header:
Which brings me back to square one, where the API spits the dummy when I use the Manager Account ID.
I've checked out this stack overflow question , but I think we're having different problems, as all my accounts have the red 'TEST ACCOUNT' flag next to them.
As a final note: there are two test client accounts, both which I've set up with quasi campaigns.
I wrote that example. You can set the client ID in the command line or the YAML file. It will not work if you use a manager account ID.
I know the terminology is confusing but that's what that API expects.
If you have any further issues with it, let me know.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.