I´m using composer to install the the google api client Packagist Google API Client.
After I installed it using composer require google/apiclient it installed like normal.
After that I tried to use it in the example below
<?php
use GoogleServiceShoppingContent;
use GoogleAuthCredentialsServiceAccountCredentials;
/**
*
*/
class GoogleShoppingContentAPI
{
private $service;
public function __construct($credentialsPath) {
// Create the credentials object
$credentials = new ServiceAccountCredentials(
ShoppingContent::CONTENT,
$credentialsPath
);
// Create the Shopping Content Service with the credentials
$this->service = new ShoppingContent(['credentials' => $credentials]);
}
public function getProducts($merchantID)
{
try {
// Fetch a list of products
$products = $this->service->products->listProducts($merchantID);
// Return the product data as an array
return $products->getResources();
} catch (GoogleServiceException $e) {
throw new Exception("Error: " . $e->getMessage());
}
}
}
However when running the code it prints out this error:
Class Fatal error: Uncaught Error: Class "GoogleAuthCredentialsServiceAccountCredentials" not found in /Users/Shared/www/inc/google.inc.php on line 15
It is in our autoload and our autoload is required before running the code aboved.
The Google namespace isnt occupied by another package aswell.
I already looked through our project and did not found any duplicate namespaces related to google.
Also reinstalling aswell composer update did not changed anything.
2
Answers
Okay, I´m a bit embarrassed to admit but I ran the composer require command in the wrong folder. So that's why it got installed but it wasn't able to be autoloaded. Shame on me. 😅
A quick look at the github source of that library suggests that the class you’re looking for isn’t there any more:
https://googleapis.github.io/google-api-php-client/main/
You probably need a more up-to-date guide to follow.
If you look at the github readme.md: https://github.com/googleapis/google-api-php-client you’ll see some examples of how to use the API now. Good luck!