Posts tagged with php

So here's the problem leading to that question: I've got a tracking script that is causing my Google Ads text ads to be disapproved for having "Malicious or unwanted software." Neither is on the script.

The PHP script is encoded using eval(gzinflate(substr(base64_decode. Since hacked websites are often encoded (again, the one in question is not hacked), I'm wondering if Google is able to recognized that the site is encoded and that's triggering the red flag.

Thanks for any help on this.

I am trying to create a web application (backend is in PHP / Laravel), with this functionality

  1. user ads a valid gmail address
  2. system checks if the address is valid and if such a address is assigned to a Google Ads Account
  3. if true, system should "somehow" retrieve the customerId of the google ads account, or all of them if there are more than one accessible from the address
  4. system checks if the ads account is an MCC account step
  5. if so, system should list all of the customers the mcc account is "handling" ...

My question is - how do I do step 3?

The "input" data I have is the e-mail address, at this point I already know that it's valid, and the account has already given permission to my application to access google ads, I have everything properly configured, but

I have no clue HOW to do it. The official API documentation is not very helpful, just like the official PHP library which I'm using, it assumes that I KNOW the customerId (or the loginCustomerId in the case of MCC accounts).

Any clue how could I do it?

I'm trying to use google_ads_api to generate keywords idea. I found an error when I execute generateKeywordsIdeas.php file.

PS C:\xampp\htdocs\google_ads_api> php GenerateKeywordIdeas.php PHP Fatal error: Uncaught Error: Class 'Google\Ads\GoogleAds\Examples\Utils\ArgumentParser' not found in C:\xampp\htdocs\google_ads_api\GenerateKeywordIdeas.php:67 Stack trace:

#0 C:\xampp\htdocs\google_ads_api\GenerateKeywordIdeas.php(212): Google\Ads\GoogleAds\Examples\Planning\GenerateKeywordIdeas::main()
#1 {main} thrown in C:\xampp\htdocs\google_ads_api\GenerateKeywordIdeas.php on line 67

Fatal error: Uncaught Error: Class 'Google\Ads\GoogleAds\Examples\Utils\ArgumentParser' not found in C:\xampp\htdocs\google_ads_api\GenerateKeywordIdeas.php:67 Stack trace:
#0 C:\xampp\htdocs\google_ads_api\GenerateKeywordIdeas.php(212): Google\Ads\GoogleAds\Examples\Planning\GenerateKeywordIdeas::main()
#1 {main} thrown in C:\xampp\htdocs\google_ads_api\GenerateKeywordIdeas.php on line 67

Here is file structure of my project

Why this error happens..? can anybody explain..?

The below output appears in my CMD (windows 10) after installing (guide here):

PHP Warning:  PHP Startup: Unable to load dynamic library 'grpc' (tried: C:\php\ext\grpc (The specified module could not be found.), C:\php\ext\php_grpc.dll (The specified module could not be found.)) in Unknown on line 0 Warning: PHP Startup: Unable to load dynamic library 'grpc' (tried: C:\php\ext\grpc (The specified module could not be found.), C:\php\ext\php_grpc.dll (The specified module could not be found.)) in Unknown on line 0 ; Notes for Windows environments : ; ; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+) ;   extension folders as well as the separate PECL DLL download (PHP 5+). ;   Be sure to appropriately set the extension_dir directive. ; ;extension=bz2 extension=curl ;extension=ffi ;extension=ftp extension=fileinfo ;extension=gd2 ;extension=gettext ;extension=gmp ;extension=intl ;extension=imap ;extension=ldap extension=mbstring ;extension=exif      ; Must be after mbstring as it depends on it ;extension=mysqli ;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client ;extension=odbc extension=openssl ;extension=pdo_firebird extension=pdo_mysql ;extension=pdo_oci ;extension=pdo_odbc ;extension=pdo_pgsql extension=pdo_sqlite ;extension=pgsql ;extension=shmop extension=grpc 

I've downloaded the correct DLL version (x64) for the right PHP version (7.4) and I can even click the location cmd tries when I run it in VS code which just opens the DLL its telling me I don't have. I've also included the extension section from my php.ini as im absoltuely at a loss at this point.

I'm developing an integration between existing CPA system and Google AdWords. Conversions are stored in the system, and the goal is to periodically, as a background task, parse conversions and send them to user's Google Ad account.

Here's what I figured so far:

  1. I need a google application to which users will grant permission to push data to their ad account.
  2. I need Oauth2 credentials to authorize my application AND users credentials to authorize the API request.

The process of creating and storing gclid is out of concern right now.

I use php client library https://github.com/googleads/googleads-php-lib, which has adsapi_php.ini configuration file. In this file, there are developer token, manager's account client ID, and OAuth2 credentials (cliendId, clientSecret, refreshToken).

However, when user gives access to my application via consent screen, I create OAuth2 object as follows:

 $oAuth2Credential = new OAuth2([         'authorizationUri'   => 'https://accounts.google.com/o/oauth2/v2/auth',         'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',         'redirectUri'        => '<myEndpoint>',         'clientId'           => '<myClientId>',         'clientSecret'       => '<myClientSecret>',         'scope'              => 'https://www.googleapis.com/auth/adwords'     ]); 

If I understand correctly, I absolutely need to have web application OAuth credentials in order to have a callback to save user's access and refresh tokens, to use them later in my background task.

1) Does this credentials and the ones in adsapi_ini.php file has to be the same?

I've tried to generate a refresh token for my web type credentials to use in conf file, but it did not work. Right now I'm able to get a valid response when I have credentials for application type 'other' in the configuration file, and 'web' application credentials in Oauth2 object for getting user credentials, but I'm not sure this is correct way to do it.

2) How to authorize API request to push data to certain user's account?

Here's sample code:

 $session = (new AdWordsSessionBuilder())         ->fromFile()         ->withOAuth2Credential($oAuth2Credential)         ->withClientCustomerId('<client-customer-id>')         ->build(); 

As I understand, session object is essential to build any further queries, including uploding conversions.

->fromFile() uses mentined configuration file to get my token and Auth data - basically authorize my application.

$oAuth2Credential is the OAuth2 object containing specific user's authorization data. The problem is that in documentation, this object is created by builder and uses the same method fromFile(), and I don't understand what data it must contain.

I store access_token and refresh_token in my database, and right now I'm building OAuth object as follows:

$oAuth2Credential = new OAuth2([         'authorizationUri'   => 'https://accounts.google.com/o/oauth2/v2/auth',         'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',         'redirectUri'        => '<myEndpoint>',         'clientId'           => '<myClientId>',         'clientSecret'       => '<myClientSecret>',         'scope'              => 'https://www.googleapis.com/auth/adwords',         'access_token'       => '<user_access_token>'     ]); 

So basically just adding access_token to parameters that I'm using for getting this token from user. It works, but doesn't look like correct way to do this.

3) How to manage user's token expiration?

Documentation says that client library automatically handles refreshing tokens, but I don't understand how it will work in my case. Do I need to pass access_token with refresh_token in OAuth object when making API request and then it will refresh automatically, or do I need separate worker to periodically refresh user tokens to keep them valid?