Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentParser not found #464

Closed
PierrickVoulet opened this issue Nov 20, 2020 · 12 comments
Closed

ArgumentParser not found #464

PierrickVoulet opened this issue Nov 20, 2020 · 12 comments
Assignees

Comments

@PierrickVoulet
Copy link
Collaborator

Hi ,Iam working with google ads iam gettings this error,please help me

Fatal error: Uncaught Error: Class 'Google\Ads\GoogleAds\examples\Utils\ArgumentParser' not found in C:\xampp\htdocs\googleads\CreateCustomer.php:48 Stack trace: #0 C:\xampp\htdocs\googleads\CreateCustomer.php(128): Google\Ads\GoogleAds\examples\AccountManagement\CreateCustomer::main() #1 {main} thrown in C:\xampp\htdocs\googleads\CreateCustomer.php on line 48

Originally posted by @GitHubgopinath in #286 (comment)

@PierrickVoulet
Copy link
Collaborator Author

Hi @GitHubgopinath - It looks like your script which is located in C:\xampp\htdocs\googleads\CreateCustomer.php is trying to call the CreateCustomer.php example?

Could you provide us with the code that you are trying to execute so that we can investigate?

@GitHubgopinath
Copy link

Hello @PierrickVoulet
Please look at this CreateCustomer.php Code

`<?php

/**

  • Copyright 2018 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.
    */

namespace Google\Ads\GoogleAds\examples\AccountManagement;

use GetOpt\GetOpt;
use Google\Ads\GoogleAds\examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\V6\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V6\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V6\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\V6\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V6\Resources\Customer;
use Google\ApiCore\ApiException;

/**

  • This example illustrates how to create a new customer under a given manager account.
  • Note: this example must be run using the credentials of a Google Ads manager account. By default,
  • the new account will only be accessible via the manager account.
    */

class CreateCustomer
{
private const MANAGER_CUSTOMER_ID = '';

public static function main()
{
    // Either pass the required parameters for this example on the command line, or insert them
    // into the constants above.
    $options = (new ArgumentParser())->parseCommandArguments([
        ArgumentNames::MANAGER_CUSTOMER_ID => GetOpt::REQUIRED_ARGUMENT
    ]);

    // Generate a refreshable OAuth2 credential for authentication.
    $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();

    // Construct a Google Ads client configured from a properties file and the
    // OAuth2 credentials above.
    $googleAdsClient = (new GoogleAdsClientBuilder())
        ->fromFile()
        ->withOAuth2Credential($oAuth2Credential)
        ->build();

    try {
        self::runExample(
            $googleAdsClient,
            $options[ArgumentNames::MANAGER_CUSTOMER_ID] ?: self::MANAGER_CUSTOMER_ID
        );
    } catch (GoogleAdsException $googleAdsException) {
        printf(
            "Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
            $googleAdsException->getRequestId(),
            PHP_EOL,
            PHP_EOL
        );
        foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
            /** @var GoogleAdsError $error */
            printf(
                "\t%s: %s%s",
                $error->getErrorCode()->getErrorCode(),
                $error->getMessage(),
                PHP_EOL
            );
        }
        exit(1);
    } catch (ApiException $apiException) {
        printf(
            "ApiException was thrown with message '%s'.%s",
            $apiException->getMessage(),
            PHP_EOL
        );
        exit(1);
    }
}

/**
 * Runs the example.
 *
 * @param GoogleAdsClient $googleAdsClient the Google Ads API client
 * @param int $managerCustomerId the manager customer ID
 */
public static function runExample(GoogleAdsClient $googleAdsClient, int $managerCustomerId)
{
    $customer = new Customer([
        'descriptive_name' => 'Account created with CustomerService on ' . date('Ymd h:i:s'),
        // For a list of valid currency codes and time zones see this documentation:
        // https://developers.google.com/adwords/api/docs/appendix/codes-formats.
        'currency_code' => 'USD',
        'time_zone' => 'America/New_York',
        // The below values are optional. For more information about URL
        // options see: https://support.google.com/google-ads/answer/6305348.
        'tracking_url_template' => '{lpurl}?device={device}',
        'final_url_suffix' => 'keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}'
    ]);

    // Issues a mutate request to create an account
    $customerServiceClient = $googleAdsClient->getCustomerServiceClient();
    $response = $customerServiceClient->createCustomerClient($managerCustomerId, $customer);

    printf(
        'Created a customer with resource name "%s" under the manager account with '
        . 'customer ID %d.%s',
        $response->getResourceName(),
        $managerCustomerId,
        PHP_EOL
    );
}

}

CreateCustomer::main();

?>`

@GitHubgopinath
Copy link

Q:-is trying to call the CreateCustomer.php example?

Ans :- Yes ,Iam running the example code given given in google ads

@GitHubgopinath
Copy link

I was dowloaded google ads library file from this Google ads api -php ,i think some of files missing in it like

use Google\Ads\GoogleAds\examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\V6\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V6\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V6\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\V6\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V6\Resources\Customer;
use Google\ApiCore\ApiException;

@PierrickVoulet
Copy link
Collaborator Author

Did you follow the getting started instructions? Feel free to let us know if you reach any issue when doing so.

@GitHubgopinath
Copy link

Hello @PierrickVoulet

Thannkyou, I will check step by step get back you,

@GitHubgopinath
Copy link

GitHubgopinath commented Nov 23, 2020

Dear @PierrickVoulet ,

  1. All things are done now working fine everything,

  2. For example i create a customer using CreateCustomer.php,but unable to fetch the account information, iam getting folloing error

ApiException was thrown with message '{ "message": "The caller does not have permission", "code": 7, "status": "PERMISSION_DENIED", "details": [ { "@type": 0, "data": "type.googleapis.com/google.ads.googleads.v6.errors.GoogleAdsFailure" }, { "@type": 0, "data": [ { "errorCode": { "authorizationError": "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#login-customer-id" } ] } ] }'.

3.While I am Creating the New Campaign Also I am getting same error of above ,how can i solve it ?
4. How many accounts i can create the google ads (or) Under the google ads manager account ?

@PierrickVoulet
Copy link
Collaborator Author

  1. Sounds good.
  2. The error message suggests that you use your manager's customer id in the login-customer-id header of the call. Please make sure that the client configuration that you use is correctly set.
  3. Same as Added support for v0_2. #2
  4. This is part of the system limits of the Google Ads API. You will find details about this specific system limit by looking for the ManagerLinkError.TOO_MANY_ACCOUNTS error.

For any further questions that are not specific to the client library but to the Google Ads API, please contact the dedicated support.

@GitHubgopinath
Copy link

Thanks for your reply

Please check this, google_ads_php.php file anything i missed

`[GOOGLE_ADS]
; Required some config parameters, which can be found at:
; https://developers.google.com/google-ads/api/docs/first-call/overview#config
developerToken = "filled with developer token"

; Required for manager accounts only: Specify the login customer ID used to authenticate API calls.
; This will be the customer ID of the authenticated manager account. You can also specify this later
; in code if your application uses multiple manager account + OAuth pairs.
; loginCustomerId = "INSERT_LOGIN_CUSTOMER_ID_HERE"

; This header is only required for methods that update the resources of an entity when permissioned
; via Linked Accounts in the Google Ads UI (AccountLink resource in the Google Ads API). Set this
; value to the customer ID of the data provider that updates the resources of the specified
; customer ID. It should be set without dashes, for example: 1234567890 instead of 123-456-7890.
; Read https://support.google.com/google-ads/answer/7365001 to learn more about Linked Accounts.
; linkedCustomerId = "INSERT_LINKED_CUSTOMER_ID_HERE"

; Optional additional settings.
; endpoint = "https://googleads.googleapis.com/"

[OAUTH2]
; Required OAuth2 credentials. Uncomment and fill in the values for the
; appropriate flow based on your use case.

; For installed application flow.
clientId = "filled with refresh Client id"
clientSecret = "filled with refresh secret code"
refreshToken=" filled with refresh token"

; For service account flow.
; jsonKeyFilePath = "INSERT_ABSOLUTE_PATH_TO_OAUTH2_JSON_KEY_FILE_HERE"
; scopes = "https://www.googleapis.com/auth/adwords"
; impersonatedEmail = "INSERT_EMAIL_OF_ACCOUNT_TO_IMPERSONATE_HERE"

[LOGGING]
; Optional logging settings.
; logFilePath = "path/to/your/file.log"
; logLevel = "INFO"

[CONNECTION]
; Optional proxy settings to be used by requests.
; If you don't have username and password, just specify host and port.
; proxy = "protocol://user:pass@host:port"

; Optional transport settings.
; By default, "grpc" is used if available otherwise "rest".
; transport = "grpc"
`

@GitHubgopinath
Copy link

I want fill these details also ?

; For service account flow. ; jsonKeyFilePath = "INSERT_ABSOLUTE_PATH_TO_OAUTH2_JSON_KEY_FILE_HERE" ; scopes = "https://www.googleapis.com/auth/adwords" ; impersonatedEmail = "INSERT_EMAIL_OF_ACCOUNT_TO_IMPERSONATE_HERE"

@PierrickVoulet
Copy link
Collaborator Author

You can uncomment and set the loginCustomerId property with your manager's customer id to follow the error message suggestion.

@PierrickVoulet PierrickVoulet self-assigned this Nov 24, 2020
@GitHubgopinath
Copy link

GitHubgopinath commented Nov 24, 2020

I got the clear idea about Google ads and adwords, up to now working fine everything It's a Great support from you Thank you so much @PierrickVoulet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants