Is it possible to get all the products from one GMC feed with the API Shopping Content python library.
Here is what I've done so far :
from google.oauth2 import service_account
from google.auth.transport.requests import Request
from google.auth.transport.requests import AuthorizedSession
import googleapiclient.discovery
# Remplacez ces valeurs par les informations de votre projet et de vos identifiants
service_account_file = 'XXX'
merchant_id = 'XXX'
feed_id = 'XXX'
# Autorisez l'accès avec le fichier de clé de service
credentials = service_account.Credentials.from_service_account_file(
service_account_file, scopes=['https://www.googleapis.com/auth/content']
)
# Initialisez l'API Shopping Content
content = googleapiclient.discovery.build('content', 'v2.1', credentials=credentials)
# Récupérez tous les produits du feed
request = content.products().list(merchantId=merchant_id)
response = request.execute()
# Parcourez les produits
if 'resources' in response:
products = response['resources']
for product in products:
#print(products)
if 'offerId' in product and feed_id in product['offerId']:
print(f"ID du produit : {product['offerId']}")
print(f"Titre du produit : {product['title']}")
print(f"État du produit : {product['contentLanguage']}")
print("----------")
# Gérez les erreurs
if 'errors' in response:
for error in response['errors']:
print(f"Erreur : {error['message']}")
I wanted to add a condition on the feed through the line
request = content.products().list(merchantId=merchant_id)
with something like this
request = content.products().list(merchantId=merchant_id, feedId=feed_id)
But it's not working. Maybe it's through the feed Service that I could achieve it but I can't find anything online that could help me.
Thank you for your help !