Hi Team,

I'm encountering a persistent issue using the `googleads/google-ads-php` 
client library (v26.0.0) with PHP 8.2.x for Service Account authentication 
within a WordPress plugin.

Despite upgrading PHP and ensuring the latest library version is installed, 
I consistently receive the following fatal error:

```
Fatal error: Uncaught Error: Call to undefined method 
Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder::withJsonKey() in 
/path/to/my/plugin/includes/class-google-ads-api-handler.php on line 58
```

*Relevant Code:*

I'm retrieving the service account JSON content (which was originally 
uploaded by the user and stored as a string in the WordPress options table) 
and decoding it into an array (`$jsonData`). Then, I attempt to build the 
credentials like this:

```php
// includes/class-google-ads-api-handler.php (around lines 37-59)

// Ensure service account JSON is properly decoded
$jsonData = get_option('gad_service_account_credentials'); // Get JSON 
string from WP DB
$decodedJson = json_decode($jsonData, true);

if (json_last_error() !== JSON_ERROR_NONE || !is_array($decodedJson)) {
    error_log('Error decoding service account JSON: ' . 
json_last_error_msg());
    // Handle error...
    return;
}
$jsonData = $decodedJson; // $jsonData is now a PHP array

// Configure the OAuth2 token builder with service account credentials 
(using FQN)
// LINE 58 BELOW IS WHERE THE ERROR OCCURS
$oAuth2Credential = (new \Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder())
    ->withJsonKey($jsonData)
    ->build();

// ... rest of client building using $oAuth2Credential
```

**Troubleshooting Steps Taken:**

1.  **PHP Version Confirmed:** Server is running PHP 8.2.x.
2.  **Library Version Confirmed:** `composer show googleads/google-ads-php` 
confirms v26.0.0 is installed.
3.  **Fresh Install:** Deleted the entire `vendor` directory and 
`composer.lock` file, then ran a fresh `composer install`. Uploaded the 
complete new `vendor` directory.
4.  **OpCache Cleared:** Restarted PHP-FPM service to ensure OpCache was 
cleared. Also tried disabling OpCache temporarily.
5.  **Code Verification:** Confirmed `$jsonData` being passed to 
`withJsonKey` is a valid PHP array decoded from the service account JSON.
6.  **Method Exists:** Manually verified that the method `withJsonKey(array 
$jsonKey)` *does* exist in the file 
`vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/OAuth2TokenBuilder.php`
 
in the installed library on the server.
7.  **Fully Qualified Namespace:** Tried using the fully qualified 
namespace `\Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder()` as shown above.
8.  **File Permissions:** Checked that web server has read access to the 
`vendor` directory files.
9.  **No Conflicts Found:** Ensured no other versions of the plugin or 
conflicting libraries seem to be loaded. The error trace points directly to 
the expected file.

Despite all this, PHP acts as if the `withJsonKey` method doesn't exist on 
the `OAuth2TokenBuilder` class. I'm running out of ideas for what could be 
causing PHP to fail to see this method.

Could there be any other environmental factor, PHP extension issue, or 
subtle autoloader conflict I might be missing? Any suggestions on further 
debugging steps would be greatly appreciated.

Thanks!

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/adwords-api/4a0402cc-609b-4023-9ace-029e8610907en%40googlegroups.com.

Reply via email to