googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
294 stars 262 forks source link

GoogleAdsException with status INVALID_ARGUMENT does not tell what exactly went wrong #113

Closed lezhnev74 closed 5 years ago

lezhnev74 commented 5 years ago

This is what I see in the log: image

Is there a way to tell what argument is invalid? This exception lacks details.

Raibaz commented 5 years ago

Hi,

Can you please provide the code that you are executing that results in this exception? Thanks

lezhnev74 commented 5 years ago

Sure, here I get an error (I think it has something to do wit han ainvalid GQL snippet): image

While this snippet does NOT raise any problems: image

Raibaz commented 5 years ago

Yes, the issue is indeed with your GAQL query: GAQL does not support SELECT *, and that is the reason why the first query is failing with INVALID_ARGUMENT.

I also agree the error message could use some improvement, I'll let the API engineers know.

lezhnev74 commented 5 years ago

It is interesting. When I enabled the logging option like this:

(new \Google\Ads\GoogleAds\Lib\V1\GoogleAdsClientBuilder())
            ->withDeveloperToken($this->clientDeveloperToken)
            ->withOAuth2Credential($this->buildOAuthCredentials($userId))
            ->withLogger($this->logger) // <----------
            ->build();

I can see that the log shows what exactly went wrong with the request. Here is a sample from the log:

[2019-06-07 13:49:30] local.NOTICE: Request
-------
Method Name: /google.ads.googleads.v1.services.GoogleAdsService/Search
Host: googleads.googleapis.com
Headers: {
    "x-goog-api-client": "gl-php\/7.2.18 gapic\/ gax\/0.38.0 grpc\/1.21.3",
    "x-goog-request-params": "customer_id=8530332597",
    "developer-token": "REDACTED"
}
Request: {"customerId":"8530332597","query":"        SELECT \n            \n            campaign_criterion.resource_name,\n            campaign_criterion.type,\n            campaign_criterion.status\n            \n            FROM campaign_criterion\n            WHERE campaign_criterion.campaign = 'customers\/8530332597\/campaigns\/2013530618' AND status = 2 "}

Response
-------
Headers: {
    "request-id": "OmmuThSFOoQugnFHeF_RFQ",
    "date": "Fri, 07 Jun 2019 13:49:30 GMT",
    "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,44,43,39\""
}

Fault
-------
Status code: 3
Details: Request contains an invalid argument.
Failure: {"errors":[{"errorCode":{"queryError":"UNRECOGNIZED_FIELD"},"message":"Unrecognized field in the query: 'status'."}]}

The Fault section has quite a detailed problem description.

This is very good!

chiragvels commented 5 years ago

@lezhnev74 ,

Can you please tell what you have defined under $this->logger.

I tried this but without any success.

$log = new Logger('TestChanel'); $stream = new StreamHandler($logPath, Logger::ERROR); $stream->setFormatter(new LineFormatter(null, null, false, true)); $log->pushHandler($stream);

Thanks

lezhnev74 commented 5 years ago

I am using a framework (Laravel) which prepares the logger for me. I just inject \Psr\Log\LoggerInterface interface and pass it in the builder. If you build Logger up manually then you'd better read manual about how your chosen PSR-3 implementation works.

PierrickVoulet commented 5 years ago

In case you did not have the chance to check it yet, there is more documentation about logging available here. HIH

chiragvels commented 5 years ago

Hi @PierrickVoulet ,

Yes I seen the Logging guide but do not know how I can use LoggerInterface. So I used Monolog logger like this and try to add GoogleAdsClientBuilder but seems I am not getting the detailed info.

    $log = new Logger('TestChanel');
    $stream = new StreamHandler('file.log', Logger::WARNING);
    $stream->setFormatter(new LineFormatter(null, null, false, true));
    $log->pushHandler($stream);

    $googleAdsClient = (new GoogleAdsClientBuilder())
            ->withOAuth2Credential(XX)
            ->withLoginCustomerId('XXXX')
            ->withLogger($log)
            ->build();

If you can guide me little bit how I use LoggerInterface will be much helpful.

Thanks,

fiboknacky commented 5 years ago

If you pass Logger:WARNING as a filter level, wouldn't it just filter those finer than WARNING level out? If you'd like to see the detailed (fine levels) information, you'd need to specify the lower level, like NOTICE, INFO or DEBUG.

chiragvels commented 5 years ago

Hello,

Yes I did that also and also set the Logger Level as Debug on Logging

[LOGGING] logFilePath = "/logs/logfile.log" logLevel = "DEBUG"

But I am not getting beyond this information.

[2019-07-04 09:58:40] TestChanel.NOTICE: Request ------- Method Name: /google.ads.googleads.v2.services.GoogleAdsService/Search Host: googleads.googleapis.com Headers: { "x-goog-api-client": "gl-php\/7.1.23 gapic\/ gax\/1.0.3 grpc\/1.20.0", "x-goog-request-params": "customer_id=1234", "developer-token": "REDACTED", "login-customer-id": "1234" } Request: {"customerId":"1234","query":"SELECT segments.date, metrics.average_cpc, metrics.clicks, metrics.conversions, metrics.conversions_from_interactions_rate, \n metrics.cost_micros, metrics.cost_per_conversion, metrics.ctr, metrics.impressions, metrics.search_absolute_top_impression_share, \n metrics.top_impression_percentage, metrics.view_through_conversions\n FROM\n customer\n WHERE\n segments.date >= 20190624 AND segments.date <= 20190630","pageSize":500} Response ------- Headers: { "request-id": "PM-K1Nh9hMqoKISJuvNv1Q", "date": "Thu, 04 Jul 2019 04:28:35 GMT", "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"" } Fault ------- Status code: 3 Details: Request contains an invalid argument. Failure: {}

fiboknacky commented 5 years ago

If you get the line "Fault", it's probably all that the server returned. And chances are your issue would be different than what's posted in this issue. As it seems the Google Ads API-related issue, could you please post in the Google Ads API forum instead? Thank you

chiragvels commented 5 years ago

Hi @fiboknacky ,

Yes I posted there as well but till now No reply to that. The link is https://groups.google.com/d/topic/adwords-api/ZApUsckdvpc/discussion

The fault message Request contains an invalid argument is same what this issue said it does not tell what exactly went wrong.

Thanks,

Raibaz commented 5 years ago

Just a question: are you setting logLevel = "DEBUG" in the .ini file and then in the code creating a logger with Logger::WARNING as the logging level?

If this is the case, be aware that the logging level you set in the code will override the logging level set in the .ini file, so this may be the reason why you don't see DEBUG log messages.

chiragvels commented 5 years ago

Ok @Raibaz ,

are you setting logLevel = "DEBUG" in the .ini file and then in the code creating a logger with Logger::WARNING as the logging level?

-> Yes, I was doing same. Now I have comment out [LOGGING] and set only Logger::DEBUG.

But Showing same error, and no information beyond this.

Response ------- Headers: { "request-id": "FVup0mtD2Jztr8D7HPnWFg", "date": "Thu, 04 Jul 2019 08:54:00 GMT", "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,44,43,39\"" } Fault ------- Status code: 3 Details: Request contains an invalid argument. Failure: {}

chiragvels commented 5 years ago

Hi @fiboknacky / @Raibaz

Can you please help here? How I can get details about error?

Thanks,

fiboknacky commented 5 years ago

I see your error for that request ID as:

[{
    error_code: "QueryError.PROHIBITED_METRIC_IN_SELECT_OR_WHERE_CLAUSE",
    error_message: "Cannot select or filter on the following metrics: 'search_absolute_top_impression_share'(could not support requested resources: 'CUSTOMER'), 'top_impression_percentage'(could not support requested resources: 'CUSTOMER'), since metric is incompatible with the resource in the FROM clause or other selected segmenting resources."
  }]
Raibaz commented 5 years ago

@chiragvels, what operating system are you on?

Additionally, please make sure that your $logPath variable points to an existing, writeable file.

chiragvels commented 5 years ago

@fiboknacky , But I could not receive any details regarding this. @Raibaz I am on PHP 7.1.23 on mac OS 10.13.6 Yes $logPath is writable and I am providing above error logs from this $logPath only.

Thanks,

chiragvels commented 5 years ago

hello,

I can see this errors on cli when using Logger:ERROR

query_error: Cannot select or filter on the following metrics: 'top_impression_percentage'(could not support requested resources: 'CUSTOMER'), 'search_absolute_top_impression_share'(could not support requested resources: 'CUSTOMER'), since metric is incompatible with the resource in the FROM clause or other selected segmenting resources.

But the error log on logpath is gone. No idea why? Thanks

lezhnev74 commented 5 years ago

@Raibaz there is an issue with the same error code that I can't understand. I am making a new request to create a responsive ad, but google rejects it with a very bold statement: Request contains an invalid argument. Is there a way to get more insights into what happened?

Here is a log message with request and response from google:

[2019-07-18 08:55:46] testing.WARNING: Request made: Host: "googleads.googleapis.com", Method: "/google.ads.googleads.v2.services.AdGroupAdService/MutateAdGroupAds", ClientCustomerId: 8530332597, RequestId: "8A8QxhLEKFNAhRoW5wroUw", IsFault: 1, FaultMessage: "None" {"cycleLabel":"4a60b57a-a659-415b-a34d-18dc5cc63daa"}
[2019-07-18 08:55:46] testing.NOTICE: Request
-------
Method Name: /google.ads.googleads.v2.services.AdGroupAdService/MutateAdGroupAds
Host: googleads.googleapis.com
Headers: {
    "x-goog-api-client": "gl-php\/7.2.18 gapic\/ gax\/1.0.3 grpc\/1.21.3",
    "x-goog-request-params": "customer_id=8530332597",
    "developer-token": "REDACTED"
}
Request: {"customerId":"8530332597","operations":[{"create":{"status":"ENABLED","adGroup":"customers\/8530332597\/adGroups\/75277337406","ad":{"finalUrls":["https:\/\/example.org\/5d30340425d71"],"responsiveDisplayAd":{"marketingImages":[{"asset":"customers\/8530332597\/assets\/1720929337"},{"asset":"customers\/8530332597\/assets\/1725022992"}],"logoImages":[{"asset":"customers\/8530332597\/assets\/1725022863"}],"headlines":[{"text":"headline"}],"longHeadline":{"text":"long headline 5d30340425a0f"},"businessName":"business name 57"}}}}]}

Response
-------
Headers: {
    "request-id": "8A8QxhLEKFNAhRoW5wroUw",
    "date": "Thu, 18 Jul 2019 08:55:42 GMT",
    "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\""
}

Fault
-------
Status code: 3
Details: Request contains an invalid argument.
Failure: {}
Raibaz commented 5 years ago

Had a look at our internal logs, and here is the error messages I found for your request id:

[{
    error_code: "ImageError.ASPECT_RATIO_NOT_ALLOWED",
    field_path: "operations[0].create.ad.responsive_display_ad.marketing_images[0].asset",
    error_message: "The aspect ratio of the image is not allowed."
  },{
    error_code: "ImageError.ASPECT_RATIO_NOT_ALLOWED",
    field_path: "operations[0].create.ad.responsive_display_ad.marketing_images[1].asset",
    error_message: "The aspect ratio of the image is not allowed."
  },{
    error_code: "ImageError.ASPECT_RATIO_NOT_ALLOWED",
    field_path: "operations[0].create.ad.responsive_display_ad.logo_images[0].asset",
    error_message: "The aspect ratio of the image is not allowed."
  },{
    error_code: "CollectionSizeError.TOO_FEW",
    field_path: "operations[0].create.ad.responsive_display_ad.descriptions.pinned_field",
    error_message: "Too few."
  },{
    error_code: "FieldError.REQUIRED",
    field_path: "operations[0].create.ad.responsive_display_ad.square_marketing_images.asset",
    error_message: "The required field was not present."
  }]

These should actually have been logged in your Failure field, I'll open an internal bug to make sure they are.

Also, please don't comment on closed issues; please open new ones if you are experiencing problems, otherwise I may not get the notifications.

Thanks!

lezhnev74 commented 5 years ago

Thank you @Raibaz ! That internal log's entries are SUPER useful! I was pulling my hairs off today trying to recognize the problem.

nihadsaleem commented 5 months ago

i have the same error, can you help me

ApiException was thrown with message: '{ "message": "Request contains an invalid argument.", "code": 3, "status": "INVALID_ARGUMENT", "details": [ { "@type": "google.ads.googleads.v16.errors.googleadsfailure-bin", "data": "" }, { "@type": "grpc-status-details-bin", "data": "" }, { "@type": "request-id", "data": "LGu13OoryHSN1XQXsqnewA" } ] }'. Request ID: 'LGu13OoryHSN1XQXsqnewA' Error Details: ''

image Screenshot 2024-05-27 122903

fiboknacky commented 5 months ago

Did you specify the wrong customer ID? It should be that of client accounts, not manager accounts.

nihadsaleem commented 5 months ago

Did you specify the wrong customer ID? It should be that of client accounts, not manager accounts.

Thank you for bringing this to my attention. I apologize for any confusion. Just to clarify, I've been using the client account ID rather than the manager account ID. If there are any further adjustments needed, please let me know

nihadsaleem commented 5 months ago

Did you specify the wrong customer ID? It should be that of client accounts, not manager accounts.

I wanted to clarify that the function I created for retrieving client names is indeed working smoothly. However, I've encountered an issue with another function I recently developed, specifically for retrieving spend details. Unfortunately, it's not functioning as intended Attachment for working method

Screenshot 2024-05-27 141551

fiboknacky commented 5 months ago

The log says otherwise. It looks like you sent a customer ID that is a manager account (33725XXXXX). Please re-run your report that your webpage_view report by specifying a client account.

nihadsaleem commented 5 months ago

The log says otherwise. It looks like you sent a customer ID that is a manager account (33725XXXXX). Please re-run your report that your webpage_view report by specifying a client account.

let me check with my manager