← back to Gmc 425 Supplemental Feed
probe-datafeeds.mjs
15 lines
import fs from 'node:fs'; import crypto from 'node:crypto';
const HOME=process.env.HOME, MERCHANT='146735262';
const SA_PATH=HOME+'/Projects/secrets-manager/gmc-sa-146735262.json';
const b64=b=>Buffer.from(b).toString('base64').replace(/=/g,'').replace(/\+/g,'-').replace(/\//g,'_');
const SA=JSON.parse(fs.readFileSync(SA_PATH,'utf8'));const now=Math.floor(Date.now()/1000);
const si=b64(JSON.stringify({alg:'RS256',typ:'JWT'}))+'.'+b64(JSON.stringify({iss:SA.client_email,scope:'https://www.googleapis.com/auth/content',aud:'https://oauth2.googleapis.com/token',iat:now,exp:now+3600}));
const s=crypto.createSign('RSA-SHA256');s.update(si);const jwt=si+'.'+b64(s.sign(SA.private_key));
const tr=await fetch('https://oauth2.googleapis.com/token',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:new URLSearchParams({grant_type:'urn:ietf:params:oauth:grant-type:jwt-bearer',assertion:jwt})});
const tok=(await tr.json()).access_token;
const H={Authorization:`Bearer ${tok}`};
const df=await (await fetch(`https://shoppingcontent.googleapis.com/content/v2.1/${MERCHANT}/datafeeds`,{headers:H})).json();
console.log('EXISTING DATAFEEDS:');
for(const d of (df.resources||[])){console.log(` id=${d.id} name="${d.name}" contentType=${d.contentType} targets=${JSON.stringify((d.targets||[]).map(t=>t.country+'/'+t.language))} fetch=${d.fetchSchedule?.fetchUrl?'URL':'manual/other'}`);}
console.log(` (${(df.resources||[]).length} datafeeds total)`);